-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test to verify
create fuels
template integrity (#2364)
- Loading branch information
1 parent
3b27bac
commit 3b00bdb
Showing
15 changed files
with
231 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-fuels": patch | ||
--- | ||
|
||
chore: add test to verify `create fuels` template integrity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
FUEL_NETWORK_URL= | ||
TEST_WALLET_PVT_KEY= | ||
PUBLISHED_NPM_VERSION= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: "Publish PR to NPM" | ||
inputs: | ||
npm-token: | ||
description: "NPM token for authenticating to NPM registry" | ||
required: true | ||
|
||
github-token: | ||
description: "GitHub token for authenticating to GitHub" | ||
required: true | ||
|
||
pr-number: | ||
description: "PR number" | ||
default: ${{ github.event.pull_request.number }} | ||
|
||
outputs: | ||
published_version: | ||
description: "Published version of the PR" | ||
value: ${{ steps.release.outputs.published_version }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Ensure NPM access | ||
shell: bash | ||
run: npm whoami | ||
env: | ||
NODE_AUTH_TOKEN: ${{ inputs.npm-token }} | ||
|
||
- name: Release to @pr-${{ inputs.pr-number }} tag on npm | ||
id: release | ||
shell: bash | ||
run: | | ||
pnpm changeset:next | ||
git add .changeset/fuel-labs-ci.md | ||
pnpm changeset version --snapshot pr-${{ inputs.pr-number }} | ||
changetsets=$(pnpm changeset publish --tag pr-${{ inputs.pr-number }}) | ||
published_version=$(echo "$changetsets" | grep -oP '@\K([0-9]+\.){2}[0-9]+-pr-${{ inputs.pr-number }}-\d+' | head -1) | ||
echo "published_version=$published_version" >> $GITHUB_OUTPUT | ||
env: | ||
NODE_AUTH_TOKEN: ${{ inputs.npm-token }} | ||
GITHUB_TOKEN: ${{ inputs.github-token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { safeExec } from '@fuel-ts/errors/test-utils'; | ||
import { execSync } from 'child_process'; | ||
|
||
import type { ProjectPaths } from './utils/bootstrapProject'; | ||
import { bootstrapProject, resetFilesystem } from './utils/bootstrapProject'; | ||
import { generateArgs } from './utils/generateArgs'; | ||
import { | ||
filterForcBuildFiles, | ||
filterOriginalTemplateFiles, | ||
getAllFiles, | ||
} from './utils/templateFiles'; | ||
|
||
const { log } = console; | ||
|
||
const PUBLISHED_NPM_VERSION = process.env.PUBLISHED_NPM_VERSION; | ||
const programsToInclude = { contract: true, predicate: true, script: true }; | ||
const availablePackages = ['pnpm']; | ||
|
||
/** | ||
* @group e2e | ||
*/ | ||
describe('`create fuels` package integrity', () => { | ||
let paths: ProjectPaths; | ||
let shouldSkip = false; | ||
|
||
beforeAll(() => { | ||
if (!PUBLISHED_NPM_VERSION) { | ||
log('Skipping live `create fuels` test'); | ||
shouldSkip = true; | ||
} | ||
}); | ||
|
||
beforeEach(() => { | ||
paths = bootstrapProject(__filename); | ||
}); | ||
|
||
afterEach(() => { | ||
resetFilesystem(paths.root); | ||
}); | ||
|
||
it.each(availablePackages)( | ||
'should perform `%s create fuels`', | ||
async (packageManager) => { | ||
if (shouldSkip) { | ||
return; | ||
} | ||
|
||
const args = generateArgs(programsToInclude, paths.root, packageManager).join(' '); | ||
const expectedTemplateFiles = await getAllFiles(paths.sourceTemplate).then((files) => | ||
filterOriginalTemplateFiles(files, programsToInclude).filter(filterForcBuildFiles) | ||
); | ||
|
||
const { error: createFuelsError } = await safeExec(() => | ||
execSync(`${packageManager} create fuels@${PUBLISHED_NPM_VERSION} ${args}`, { | ||
stdio: 'inherit', | ||
}) | ||
); | ||
|
||
const actualTemplateFiles = await getAllFiles(paths.root); | ||
expect(createFuelsError).toBeUndefined(); | ||
expect(actualTemplateFiles.sort()).toEqual(expectedTemplateFiles.sort()); | ||
}, | ||
{ timeout: 30000 } | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { ProgramsToInclude } from '../../src/cli'; | ||
|
||
export const generateArgs = ( | ||
programsToInclude: ProgramsToInclude, | ||
projectName?: string, | ||
packageManager: string = 'pnpm' | ||
): string[] => { | ||
const args = []; | ||
if (projectName) { | ||
args.push(projectName); | ||
} | ||
if (programsToInclude.contract) { | ||
args.push('-c'); | ||
} | ||
if (programsToInclude.predicate) { | ||
args.push('-p'); | ||
} | ||
if (programsToInclude.script) { | ||
args.push('-s'); | ||
} | ||
args.push(`--${packageManager}`); | ||
return args; | ||
}; | ||
|
||
export const generateArgv = ( | ||
programsToInclude: ProgramsToInclude, | ||
projectName?: string | ||
): string[] => ['', '', ...generateArgs(programsToInclude, projectName)]; |
Oops, something went wrong.