aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/sync-examples.yml
blob: 45d127447a738b0b0600aff662d6cc41fa9c2408 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Sync examples

on:
  workflow_dispatch:
    inputs:
      checkout-ref:
        type: string
        required: false
      skip-unchanged-check:
        type: boolean
        default: false
      dry-run:
        type: boolean
        default: false
  push:
    branches:
      - main

# Automatically cancel in-progress actions on the same branch
concurrency:
  group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
  cancel-in-progress: true

permissions:
  # Allow auto-branch-sync-action to git push
  contents: write

jobs:
  sync:
    name: Sync branches
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 2 # fetch 2 to compare with previous commit for changes
          ref: ${{ inputs.checkout-ref }}

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

      - name: Get pre mode of changesets
        id: pre
        run: |
          if [ -f ./.changeset/pre.json ]; then
            pre_value=$(jq -r '.tag' ./.changeset/pre.json)
            echo "value=$pre_value" >> $GITHUB_OUTPUT
          fi

      # 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 stable to latest and examples/* branches
        if: steps.detect.outputs.has-changesets == 'false' && github.ref == 'refs/heads/main' && steps.pre.outputs.value == ''
        uses: bluwy/auto-branch-sync-action@a72b09dc60911f56a1e7093a069f24480ca3d2ab # v1.0.1
        with:
          map: |
            / -> latest
            /examples/* -> examples/*
          skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }}
          dry-run: ${{ inputs.dry-run == true }}

      - name: Sync prerelease to alpha branch
        if: steps.detect.outputs.has-changesets == 'false' && steps.pre.outputs.value == 'alpha'
        uses: bluwy/auto-branch-sync-action@a72b09dc60911f56a1e7093a069f24480ca3d2ab # v1.0.1
        with:
          map: / -> alpha
          skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }}
          dry-run: ${{ inputs.dry-run == true }}

      - name: Sync prerelease to beta branch
        if: steps.detect.outputs.has-changesets == 'false' && steps.pre.outputs.value == 'beta'
        uses: bluwy/auto-branch-sync-action@a72b09dc60911f56a1e7093a069f24480ca3d2ab # v1.0.1
        with:
          map: / -> beta
          skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }}
          dry-run: ${{ inputs.dry-run == true }}

      - name: Sync prerelease to rc branch
        if: steps.detect.outputs.has-changesets == 'false' && steps.pre.outputs.value == 'rc'
        uses: bluwy/auto-branch-sync-action@a72b09dc60911f56a1e7093a069f24480ca3d2ab # v1.0.1
        with:
          map: / -> rc
          skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }}
          dry-run: ${{ inputs.dry-run == true }}