|
| 1 | +# In TypeScript actions, `dist/` is a special directory. When you reference |
| 2 | +# an action with the `uses:` property, `dist/index.js` is the code that will be |
| 3 | +# run. For this project, the `dist/index.js` file is transpiled from other |
| 4 | +# source files. This workflow ensures the `dist/` directory contains the |
| 5 | +# expected transpiled code. |
| 6 | +# |
| 7 | +# If this workflow is run from a feature branch, it will act as an additional CI |
| 8 | +# check and fail if the checked-in `dist/` directory does not match what is |
| 9 | +# expected from the build. |
| 10 | +name: check-dist |
| 11 | +on: [push, pull_request] |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-dist: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Setup Node.js |
| 24 | + uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + cache: npm |
| 27 | + node-version-file: .nvmrc |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + run: npm ci --prefer-offline |
| 31 | + |
| 32 | + - name: Build artifact |
| 33 | + run: npm run build |
| 34 | + |
| 35 | + # This will fail the workflow if the `dist/` directory is different than expected. |
| 36 | + - name: Compare Directories |
| 37 | + run: | |
| 38 | + if [ ! -d dist/ ]; then |
| 39 | + echo "Expected dist/ directory does not exist. See status below:" |
| 40 | + ls -la ./ |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then |
| 44 | + echo "Detected uncommitted changes after build. See status below:" |
| 45 | + git diff --ignore-space-at-eol --text dist/ |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | +
|
| 49 | + # If `dist/` was different than expected, upload the expected version as a workflow artifact. |
| 50 | + - if: failure() |
| 51 | + name: Upload Artifact |
| 52 | + uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: dist |
| 55 | + path: dist/ |
0 commit comments