From db4d7f66f0460e68eaba2f33cbc43042442138d8 Mon Sep 17 00:00:00 2001 From: Tristan Menzel Date: Wed, 25 Sep 2024 09:54:51 -0700 Subject: [PATCH] Test ci build --- .github/workflows/node-ci.yml | 157 ++++++++++++++++++++++++++++++++++ .github/workflows/pr.yml | 13 ++- 2 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/node-ci.yml diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml new file mode 100644 index 00000000..6f893160 --- /dev/null +++ b/.github/workflows/node-ci.yml @@ -0,0 +1,157 @@ +on: + workflow_call: + inputs: + node-version: + required: false + type: string + default: 18.x + working-directory: + required: false + type: string + default: '.' + lint-script: + required: false + type: string + default: npm run lint --if-present + compile-script: + required: false + type: string + default: npm run check-types --if-present + pre-test-script: + required: false + type: string + test-script: + required: false + type: string + default: npm run test --if-present + test-environment-variables: + required: false + type: string + default: '{}' + output-test-results: + required: false + type: boolean + default: false + test-results-file-pattern: + required: false + type: string + default: '**/test-results.xml' + audit-script: + required: false + type: string + default: npm audit + build-script: + required: false + type: string + default: npm run build + run-build: + required: false + type: boolean + default: false + run-commit-lint: + required: false + type: boolean + default: false + commit-lint-script: + required: false + type: string + default: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose + pre-run-script: + required: false + type: string + artifact-name: + required: false + type: string + artifact-path: + required: false + type: string + default: . + secrets: + npm-auth-token: + description: NPM auth token (don't pass in on a PR build on a public repository) + required: false + +jobs: + node-ci: + runs-on: ubuntu-latest + + defaults: + run: + shell: bash + working-directory: ${{ inputs.working-directory }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # setup node + private repo access + - name: Use Node.js ${{ inputs.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node-version }} + registry-url: 'https://npm.pkg.github.com' + scope: '@makerxstudio' + cache: 'npm' + cache-dependency-path: ${{ inputs.working-directory }}/package-lock.json + + - name: Pre-run + if: ${{ inputs.pre-run-script }} + run: ${{ inputs.pre-run-script }} + + # run npm ci preventing script access to npm auth token + - run: npm ci --ignore-scripts + env: + NODE_AUTH_TOKEN: ${{ secrets.npm-auth-token || secrets.GITHUB_TOKEN }} + # allow scripts to run without npm auth token + - run: npm rebuild && npm run prepare --if-present + + # run all the CI scripts + - name: 'Commit lint' + if: ${{ inputs.run-commit-lint }} + run: ${{ inputs.commit-lint-script }} + + - name: Lint + run: ${{ inputs.lint-script }} + + - name: Compile + run: ${{ inputs.compile-script }} + + - name: Pre-test + if: ${{ inputs.pre-test-script }} + run: ${{ inputs.pre-test-script }} + + - name: Test + run: ${{ inputs.test-script }} + env: ${{ fromJson(inputs.test-environment-variables) }} + + #Requires permissions.checks: write + - name: Publish test results + if: ${{ inputs.output-test-results }} + uses: phoenix-actions/test-reporting@v10 + with: + name: Test results + path: ${{ inputs.test-results-file-pattern }} + reporter: jest-junit + output-to: checks + fail-on-error: false + + - name: Audit + run: ${{ inputs.audit-script }} + + - name: Build + if: ${{ inputs.run-build }} + run: ${{ inputs.build-script }} + # CDK infrastructure build calls npm ci on /infrastructure/build, which may fail without NODE_AUTH_TOKEN + env: + NODE_AUTH_TOKEN: ${{ secrets.npm-auth-token || secrets.GITHUB_TOKEN }} + + - name: Publish artifact + if: ${{ inputs.artifact-name }} + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: ${{ inputs.artifact-path }} + + diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 7fdd43dd..ed461e84 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -14,14 +14,18 @@ permissions: jobs: ci-algo-ts: - uses: makerxstudio/shared-config/.github/workflows/node-ci.yml@main + uses: .github/workflows/node-ci.yml@main with: node-version: 20.x run-build: true audit-script: npm run audit working-directory: packages/algo-ts + artifact-name: algo-ts + artifact-path: dist/* ci-algo-ts-testing: - uses: makerxstudio/shared-config/.github/workflows/node-ci.yml@main + uses: .github/workflows/node-ci.yml@main + needs: + - ci-algo-ts with: node-version: 20.x run-build: true @@ -29,7 +33,10 @@ jobs: audit-script: npm run audit working-directory: packages/algo-ts-testing ci-puya-ts: - uses: makerxstudio/shared-config/.github/workflows/node-ci.yml@main + uses: .github/workflows/node-ci.yml@main + needs: + - ci-algo-ts + - ci-algo-ts-testing with: node-version: 20.x run-build: true