|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + node-version: |
| 5 | + required: false |
| 6 | + type: string |
| 7 | + default: 18.x |
| 8 | + working-directory: |
| 9 | + required: false |
| 10 | + type: string |
| 11 | + default: '.' |
| 12 | + lint-script: |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: npm run lint --if-present |
| 16 | + compile-script: |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: npm run check-types --if-present |
| 20 | + pre-test-script: |
| 21 | + required: false |
| 22 | + type: string |
| 23 | + test-script: |
| 24 | + required: false |
| 25 | + type: string |
| 26 | + default: npm run test --if-present |
| 27 | + test-environment-variables: |
| 28 | + required: false |
| 29 | + type: string |
| 30 | + default: '{}' |
| 31 | + output-test-results: |
| 32 | + required: false |
| 33 | + type: boolean |
| 34 | + default: false |
| 35 | + test-results-file-pattern: |
| 36 | + required: false |
| 37 | + type: string |
| 38 | + default: '**/test-results.xml' |
| 39 | + audit-script: |
| 40 | + required: false |
| 41 | + type: string |
| 42 | + default: npm audit |
| 43 | + build-script: |
| 44 | + required: false |
| 45 | + type: string |
| 46 | + default: npm run build |
| 47 | + run-build: |
| 48 | + required: false |
| 49 | + type: boolean |
| 50 | + default: false |
| 51 | + run-commit-lint: |
| 52 | + required: false |
| 53 | + type: boolean |
| 54 | + default: false |
| 55 | + commit-lint-script: |
| 56 | + required: false |
| 57 | + type: string |
| 58 | + default: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose |
| 59 | + pre-run-script: |
| 60 | + required: false |
| 61 | + type: string |
| 62 | + upload-artifact-name: |
| 63 | + required: false |
| 64 | + type: string |
| 65 | + upload-artifact-path: |
| 66 | + required: false |
| 67 | + description: The full path to the artifact directory, this path does not take working-directory into account |
| 68 | + type: string |
| 69 | + default: . |
| 70 | + |
| 71 | + download-artifact-name: |
| 72 | + required: false |
| 73 | + type: string |
| 74 | + download-artifact-pattern: |
| 75 | + required: false |
| 76 | + type: string |
| 77 | + download-artifact-path: |
| 78 | + required: false |
| 79 | + description: The full path to the artifact directory, this path does not take working-directory into account |
| 80 | + type: string |
| 81 | + default: . |
| 82 | + |
| 83 | + secrets: |
| 84 | + npm-auth-token: |
| 85 | + description: NPM auth token (don't pass in on a PR build on a public repository) |
| 86 | + required: false |
| 87 | + |
| 88 | +jobs: |
| 89 | + node-ci: |
| 90 | + runs-on: ubuntu-latest |
| 91 | + |
| 92 | + defaults: |
| 93 | + run: |
| 94 | + shell: bash |
| 95 | + working-directory: ${{ inputs.working-directory }} |
| 96 | + |
| 97 | + steps: |
| 98 | + - name: Checkout |
| 99 | + uses: actions/checkout@v4 |
| 100 | + with: |
| 101 | + fetch-depth: 0 |
| 102 | + |
| 103 | + # setup node + private repo access |
| 104 | + - name: Use Node.js ${{ inputs.node-version }} |
| 105 | + uses: actions/setup-node@v4 |
| 106 | + with: |
| 107 | + node-version: ${{ inputs.node-version }} |
| 108 | + registry-url: 'https://npm.pkg.github.com' |
| 109 | + scope: '@makerxstudio' |
| 110 | + cache: 'npm' |
| 111 | + cache-dependency-path: ${{ inputs.working-directory }}/package-lock.json |
| 112 | + |
| 113 | + - name: Download artifacts |
| 114 | + if: ${{ inputs.download-artifact-name || inputs.download-artifact-pattern }} |
| 115 | + uses: actions/download-artifact@v4 |
| 116 | + with: |
| 117 | + name: ${{ inputs.download-artifact-name }} |
| 118 | + pattern: ${{ inputs.download-artifact-pattern }} |
| 119 | + path: ${{ inputs.download-artifact-path }} |
| 120 | + |
| 121 | + - name: Pre-run |
| 122 | + if: ${{ inputs.pre-run-script }} |
| 123 | + run: ${{ inputs.pre-run-script }} |
| 124 | + |
| 125 | + # run npm ci preventing script access to npm auth token |
| 126 | + - run: npm ci --ignore-scripts |
| 127 | + env: |
| 128 | + NODE_AUTH_TOKEN: ${{ secrets.npm-auth-token || secrets.GITHUB_TOKEN }} |
| 129 | + # allow scripts to run without npm auth token |
| 130 | + - run: npm rebuild && npm run prepare --if-present |
| 131 | + |
| 132 | + # run all the CI scripts |
| 133 | + - name: 'Commit lint' |
| 134 | + if: ${{ inputs.run-commit-lint }} |
| 135 | + run: ${{ inputs.commit-lint-script }} |
| 136 | + |
| 137 | + - name: Lint |
| 138 | + run: ${{ inputs.lint-script }} |
| 139 | + |
| 140 | + - name: Compile |
| 141 | + run: ${{ inputs.compile-script }} |
| 142 | + |
| 143 | + - name: Pre-test |
| 144 | + if: ${{ inputs.pre-test-script }} |
| 145 | + run: ${{ inputs.pre-test-script }} |
| 146 | + |
| 147 | + - name: Test |
| 148 | + run: ${{ inputs.test-script }} |
| 149 | + env: ${{ fromJson(inputs.test-environment-variables) }} |
| 150 | + |
| 151 | + #Requires permissions.checks: write |
| 152 | + - name: Publish test results |
| 153 | + if: ${{ inputs.output-test-results }} |
| 154 | + uses: phoenix-actions/test-reporting@v10 |
| 155 | + with: |
| 156 | + name: Test results |
| 157 | + path: ${{ inputs.test-results-file-pattern }} |
| 158 | + reporter: jest-junit |
| 159 | + output-to: checks |
| 160 | + fail-on-error: false |
| 161 | + |
| 162 | + - name: Audit |
| 163 | + run: ${{ inputs.audit-script }} |
| 164 | + |
| 165 | + - name: Build |
| 166 | + if: ${{ inputs.run-build }} |
| 167 | + run: ${{ inputs.build-script }} |
| 168 | + # CDK infrastructure build calls npm ci on /infrastructure/build, which may fail without NODE_AUTH_TOKEN |
| 169 | + env: |
| 170 | + NODE_AUTH_TOKEN: ${{ secrets.npm-auth-token || secrets.GITHUB_TOKEN }} |
| 171 | + |
| 172 | + - name: Publish artifact |
| 173 | + if: ${{ inputs.upload-artifact-name }} |
| 174 | + uses: actions/upload-artifact@v4 |
| 175 | + with: |
| 176 | + name: ${{ inputs.upload-artifact-name }} |
| 177 | + path: ${{ inputs.upload-artifact-path }} |
| 178 | + |
| 179 | + |
0 commit comments