|
1 | | -# `dist/index.js` is a special file in Actions. |
2 | | -# When you reference an action with `uses:` in a workflow, |
3 | | -# `index.js` is the code that will run. |
4 | | -# For our project, we generate this file through a build process from other source files. |
5 | | -# We need to make sure the checked-in `index.js` actually matches what we expect it to be. |
6 | | -name: Check dist/ |
| 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 Transpiled JavaScript |
7 | 11 |
|
8 | 12 | on: |
9 | 13 | push: |
|
16 | 20 | paths-ignore: |
17 | 21 | - '**.md' |
18 | 22 | workflow_dispatch: |
| 23 | + |
19 | 24 | permissions: |
20 | 25 | contents: read |
21 | 26 |
|
22 | 27 | jobs: |
23 | 28 | check-dist: |
| 29 | + name: Check dist/ |
24 | 30 | runs-on: ubuntu-latest |
25 | 31 |
|
26 | 32 | steps: |
27 | | - - uses: actions/checkout@v4 |
| 33 | + - name: Checkout |
| 34 | + id: checkout |
| 35 | + uses: actions/checkout@v4 |
28 | 36 |
|
29 | | - - name: Set Node.js 20.x |
| 37 | + - name: Setup Node.js |
| 38 | + id: setup-node |
30 | 39 | uses: actions/setup-node@v4 |
31 | 40 | with: |
32 | | - node-version: 20.x |
| 41 | + node-version-file: .node-version |
33 | 42 | cache: npm |
34 | 43 |
|
35 | | - - name: Install dependencies |
| 44 | + - name: Install Dependencies |
| 45 | + id: install |
36 | 46 | run: npm ci |
37 | 47 |
|
38 | | - - name: Rebuild the dist/ directory |
39 | | - run: npm run build |
| 48 | + - name: Build dist/ Directory |
| 49 | + id: build |
| 50 | + run: npm run bundle |
40 | 51 |
|
41 | | - - name: Compare the expected and actual dist/ directories |
| 52 | + # This will fail the workflow if the `dist/` directory is different than |
| 53 | + # expected. |
| 54 | + - name: Compare Directories |
| 55 | + id: diff |
42 | 56 | run: | |
43 | | - if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then |
44 | | - echo "Detected uncommitted changes after build. See status below:" |
45 | | - git diff |
| 57 | + if [ ! -d dist/ ]; then |
| 58 | + echo "Expected dist/ directory does not exist. See status below:" |
| 59 | + ls -la ./ |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then |
| 63 | + echo "Detected uncommitted changes after build. See status below:" |
| 64 | + git diff --ignore-space-at-eol --text dist/ |
46 | 65 | exit 1 |
47 | 66 | fi |
48 | | - id: diff |
49 | 67 |
|
50 | | - # If index.js was different than expected, upload the expected version as an artifact |
51 | | - - uses: actions/upload-artifact@v4 |
52 | | - if: ${{ failure() && steps.diff.conclusion == 'failure' }} |
| 68 | + # If `dist/` was different than expected, upload the expected version as a |
| 69 | + # workflow artifact. |
| 70 | + - if: ${{ failure() && steps.diff.outcome == 'failure' }} |
| 71 | + name: Upload Artifact |
| 72 | + id: upload |
| 73 | + uses: actions/upload-artifact@v4 |
53 | 74 | with: |
54 | 75 | name: dist |
55 | 76 | path: dist/ |
0 commit comments