mirror of
https://github.com/actions/add-to-project.git
synced 2026-01-10 04:34:29 +08:00
65 lines
2.4 KiB
YAML
65 lines
2.4 KiB
YAML
# `dist/index.js` is a special file in Actions.
|
||
# When you reference an action with `uses:` in a workflow,
|
||
# `index.js` is the code that will run.
|
||
# For our project, we generate this file through a build process from other source files.
|
||
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
|
||
name: Check dist/
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- main
|
||
paths-ignore:
|
||
- '**.md'
|
||
pull_request:
|
||
paths-ignore:
|
||
- '**.md'
|
||
|
||
env:
|
||
# A pipe-separated array of files to ignore when comparing the expected and actual dist/ directories,
|
||
# which are used as a regular expression filter in the `grep` command.
|
||
FILES_TO_IGNORE: 'index.js.map|sourcemap-register.js'
|
||
|
||
jobs:
|
||
check-dist:
|
||
runs-on: ubuntu-latest
|
||
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- name: Set Node.js 20.x
|
||
uses: actions/setup-node@v3
|
||
with:
|
||
node-version: 20.x
|
||
cache: npm
|
||
|
||
- name: Install dependencies
|
||
run: npm ci
|
||
|
||
- name: Rebuild the dist/ directory
|
||
run: |
|
||
npm run build:compile
|
||
npm run build:package
|
||
|
||
- name: Compare the expected and actual dist/ directories
|
||
run: |
|
||
# Get a list of files that are different between the checked-in dist/ directory and the generated dist/ directory,
|
||
# then trim the list to remove any leading or trailing whitespace.
|
||
CHANGED_FILES=$(git diff --ignore-space-at-eol --name-only dist/ | grep -vE "$FILES_TO_IGNORE" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||
if [ -n "$CHANGED_FILES" ]; then
|
||
echo "\n❗️ Detected uncommitted changes after build (see diff output below)." >&2
|
||
echo "This indicates that the dist/ directory is out of sync with the checked-in index.js.\n" >&2
|
||
echo "⭐️ If the changes below are expected, run 'npm run build:compile && npm run build:package' and commit the output files.\n" >&2
|
||
# Run `git diff` for each line/file in $CHANGED_FILES:
|
||
echo "$CHANGED_FILES" | xargs -I {} git diff --ignore-space-at-eol --text -- {}
|
||
exit 1
|
||
fi
|
||
id: diff
|
||
|
||
# If index.js was different than expected, upload the expected version as an artifact
|
||
- uses: actions/upload-artifact@v4
|
||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||
with:
|
||
name: dist
|
||
path: dist/
|