chore(ci): automatically handle dist folder in PRs and releases #901
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR | |
on: | |
pull_request: | |
merge_group: | |
jobs: | |
test: | |
name: Test Action | |
if: github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./ | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
add_markdown: | | |
--- | |
# Things! | |
## Excitement! | |
[Links!](https://google.ca) | |
`Code!` | |
- uses: ./ | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
limit_to_pr_opened: true | |
add_markdown: | | |
--- | |
# Things! | |
## Excitement! | |
[Links!](https://google.ca) | |
`Code!` | |
dist: | |
name: Check dist/ | |
if: github.event_name != 'pull_request' | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# For push, later | |
ref: ${{ github.head_ref }} | |
- uses: actions/[email protected] | |
with: | |
node-version: 20.x | |
- name: Rebuild the dist/ directory | |
run: | | |
npm ci | |
npm run build | |
npm run package | |
- name: Commit any changes to dist/ | |
run: | | |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then | |
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
git config --global user.name "${GITHUB_ACTOR}" | |
git add . | |
git commit -m "Rebuild dist/ directory" | |
git push origin HEAD:${{ github.head_ref }} | |
fi | |
- name: Purposeful fail | |
run: exit 1 | |
results: | |
name: PR Results | |
needs: [test, dist] | |
if: always() | |
runs-on: ubuntu-22.04 | |
steps: | |
- if: contains(needs.*.result, 'failure') | |
run: echo "At least one job has failed." && exit 1 | |
- run: echo "Success!" | |
dump: | |
name: Dump context | |
runs-on: ubuntu-latest | |
env: | |
CONTEXT: ${{ toJson(github) }} | |
steps: | |
- run: echo "${CONTEXT}" |