mirror of
https://github.com/nick-fields/retry.git
synced 2026-02-09 22:58:02 +00:00
patch: re-run CI via label when changes found
This commit is contained in:
47
.github/workflows/ci_cd.yml
vendored
47
.github/workflows/ci_cd.yml
vendored
@@ -8,6 +8,11 @@ concurrency:
|
|||||||
on:
|
on:
|
||||||
# only on PRs into and merge to default branch
|
# only on PRs into and merge to default branch
|
||||||
pull_request:
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- synchronize
|
||||||
|
- reopened
|
||||||
|
- labeled
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
push:
|
push:
|
||||||
@@ -16,9 +21,11 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
BRANCH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}
|
BRANCH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}
|
||||||
|
PR_TRIGGERED: ${{ github.event_name == 'pull_request' && github.event.action != 'labeled' }}
|
||||||
jobs:
|
jobs:
|
||||||
setup:
|
setup:
|
||||||
|
# Skip running if labeled event but not rerun, otehrwise its a supported trigger event
|
||||||
|
if: ${{ github.event.label.name == 'rerun' || github.event.action != 'labeled' }}
|
||||||
name: Setup
|
name: Setup
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
@@ -30,22 +37,42 @@ jobs:
|
|||||||
ref: ${{ env.BRANCH }}
|
ref: ${{ env.BRANCH }}
|
||||||
- name: Setup and cache for later jobs
|
- name: Setup and cache for later jobs
|
||||||
uses: ./.github/actions/setup
|
uses: ./.github/actions/setup
|
||||||
# GHA requires bundled code, and we bundle automatically via pre-commit hook, but most contributions come in through UI which skips hooks.
|
# GHA requires bundled code to be commited so we bundle automatically via pre-commit hook. However, most contributions come in through the GH UI which skips hooks.
|
||||||
# So bundle again here to ensure was not skipped, and if so commit the changes to ensure we're testing the correct code.
|
# So bundle again here just in case, and if changes are found then commit them to ensure we're testing the correct code.
|
||||||
- name: Re-bundle and commit changes if found
|
# But GHA does not trigger on changes made via the default GH token, so we need to label the PR to re-run CI.
|
||||||
# Don't re-bundle on on default branch
|
# Alternatives could be using a PAT (rotation/security burden), GH App (overkill/maintenance), or something like pre-commit.ci (not convincing). Lets try this first though
|
||||||
if: ${{ env.BRANCH != 'master' }}
|
- name: Check for bundle changes after install
|
||||||
|
# Only run if not a push event since we only trigger this on the default branch and we don't want to make any non-PR changes there
|
||||||
|
if: ${{ github.event_name != 'push' }}
|
||||||
|
id: changes
|
||||||
run: |
|
run: |
|
||||||
pnpm bundle
|
|
||||||
if [[ -n "$(git status --porcelain)" ]]; then
|
if [[ -n "$(git status --porcelain)" ]]; then
|
||||||
|
echo "CHANGES_FOUND=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "No changes detected."
|
||||||
|
echo "CHANGES_FOUND=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
- name: Commit and push changes if found
|
||||||
|
if: ${{ steps.changes.outputs.CHANGES_FOUND == 'true' }}
|
||||||
|
run: |
|
||||||
git config --global user.name "github-actions[bot]"
|
git config --global user.name "github-actions[bot]"
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
git add .
|
git add .
|
||||||
git commit -m "patch: regenerated bundle"
|
git commit -m "patch: regenerated bundle"
|
||||||
git push
|
git push
|
||||||
else
|
- name: Label PR to re-trigger CI
|
||||||
echo "No changes detected."
|
if: ${{ steps.changes.outputs.CHANGES_FOUND == 'true' }}
|
||||||
fi
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
gh pr edit ${{ github.event.pull_request.number }} --add-label "rerun"
|
||||||
|
- name: Remove label after clean re-run
|
||||||
|
# Only remove label if the PR was labeled with rerun and no changes were found. Changes found indicate a problem since they should have been previously committed
|
||||||
|
if: ${{ steps.changes.outputs.CHANGES_FOUND == 'false' && github.event.label.name == 'rerun' }}
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
gh pr edit ${{ github.event.pull_request.number }} --remove-label "rerun"
|
||||||
|
|
||||||
ci_unit:
|
ci_unit:
|
||||||
name: Run Unit Tests
|
name: Run Unit Tests
|
||||||
|
|||||||
Reference in New Issue
Block a user