Skip to content

Commit

Permalink
Simplify update check
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 4, 2024
1 parent 402acc7 commit 70e1537
Showing 1 changed file with 11 additions and 44 deletions.
55 changes: 11 additions & 44 deletions .github/workflows/sync-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,7 @@ permissions:
contents: write

jobs:
check_for_update:
# Only allow running on `main` and `next` branch to prevent accidental sync overridding
if: ${{ github.repository_owner == 'withastro' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/next') }}
name: Check for Updates
runs-on: ubuntu-latest
outputs:
run_job: ${{ steps.check_files.outputs.run_job }}
steps:
- uses: actions/checkout@v4

- name: Setup PNPM
uses: pnpm/action-setup@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Check Modified
run: pnpm exec changeset status --output ./status.json

- name: Check Output
id: check_files
run: |
output=`echo $(cat status.json)`
if [[ $output = '{ "changesets": [], "releases": [] }' ]]
then
echo 'No changeset found'
echo "run_job=true" >> $GITHUB_OUTPUT
else
echo 'changes found, push to latest skipped'
echo "run_job=false" >> $GITHUB_OUTPUT
fi
sync:
needs: check_for_update
if: needs.check_for_update.outputs.run_job == 'true'
name: Sync branches
runs-on: ubuntu-latest
steps:
Expand All @@ -73,16 +33,23 @@ jobs:
with:
fetch-depth: 2 # fetch 2 to compare with previous commit for changes

- name: Detect changesets
uses: bluwy/detect-changesets-action@v1
id: detect

# We only do sync if there are no changesets, so we don't accidentally allow users
# to clone examples that may rely on unreleased code

- name: Sync from main branch to latest branch
if: github.ref == 'refs/heads/main'
if: steps.detect.outputs.has-changesets == 'false' && github.ref == 'refs/heads/main'
uses: bluwy/auto-branch-sync-action@v1
with:
map: / -> latest
skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }}
dry-run: ${{ inputs.dry-run == true }}

- name: Check .changeset/pre.json for matching tag
if: github.ref == 'refs/heads/next'
if: steps.detect.outputs.has-changesets == 'false' && github.ref == 'refs/heads/next'
id: check-pre-mode
run: |
if [ -f ./.changeset/pre.json ]; then
Expand All @@ -94,15 +61,15 @@ jobs:
fi
- name: Sync from next branch to alpha branch
if: steps.check-pre-mode.outputs.alpha == 'true'
if: steps.detect.outputs.has-changesets == 'false' && steps.check-pre-mode.outputs.alpha == 'true'
uses: bluwy/auto-branch-sync-action@v1
with:
map: / -> alpha
skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }}
dry-run: ${{ inputs.dry-run == true }}

- name: Sync from next branch to beta branch
if: steps.check-pre-mode.outputs.beta == 'true'
if: steps.detect.outputs.has-changesets == 'false' && steps.check-pre-mode.outputs.beta == 'true'
uses: bluwy/auto-branch-sync-action@v1
with:
map: / -> beta
Expand Down

0 comments on commit 70e1537

Please sign in to comment.