Sync Branches from Upstream #134
This file contains hidden or 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: Sync Branches from Upstream | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| # Run daily at 2 AM UTC | |
| - cron: "0 2 * * *" | |
| jobs: | |
| get-branches: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| branches: ${{ steps.filter-branches.outputs.branches }} | |
| steps: | |
| - name: Get branches to sync | |
| id: filter-branches | |
| run: | | |
| # Use GitHub API to get branches directly - much faster than git clone | |
| branches=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/${{ github.repository_owner }}/server/branches?per_page=100" | \ | |
| jq -r '.[] | select(.name | test("^(stable[0-9]{2}|master)$")) | .name' | sort) | |
| # Convert to JSON array for matrix | |
| json_branches="[" | |
| first=true | |
| for branch in $branches; do | |
| if [ "$first" = true ]; then | |
| first=false | |
| else | |
| json_branches+="," | |
| fi | |
| json_branches+="\"$branch\"" | |
| done | |
| json_branches+="]" | |
| echo "branches=$json_branches" >> $GITHUB_OUTPUT | |
| echo "Found branches to sync: $json_branches" | |
| sync-branches: | |
| needs: get-branches | |
| runs-on: ubuntu-latest | |
| environment: server-sync | |
| strategy: | |
| matrix: | |
| branch: ${{ fromJson(needs.get-branches.outputs.branches) }} | |
| fail-fast: false | |
| steps: | |
| - name: Restore cached git repository | |
| uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | |
| with: | |
| path: .git | |
| key: git-repo-upstream | |
| - name: Checkout upstream ${{ matrix.branch }} | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| repository: nextcloud/server | |
| ref: ${{ matrix.branch }} | |
| fetch-depth: 0 | |
| token: ${{ secrets.WORKFLOW_TOKEN }} | |
| - name: Add releases remote | |
| continue-on-error: true | |
| run: | | |
| git remote add releases https://github.com/nextcloud-releases/server.git | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Fetch releases remote | |
| run: | | |
| git fetch releases | |
| - name: Force sync to releases | |
| env: | |
| WORKFLOW_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} | |
| run: | | |
| # Force push the upstream branch to releases | |
| git push https://x-access-token:${{ secrets.WORKFLOW_TOKEN }}@github.com/nextcloud-releases/server.git ${{ matrix.branch }}:${{ matrix.branch }} --force | |
| # This is a trick to force update the cache | |
| # https://github.com/actions/cache/issues/342 | |
| - name: Delete old cache | |
| if: matrix.branch == 'master' | |
| continue-on-error: true | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| # Using `--repo` makes it so that this step doesn't require checking out the | |
| # repo first. | |
| run: gh cache delete --repo ${{ github.repository }} git-repo-upstream | |
| - name: Save repository to cache | |
| if: matrix.branch == 'master' | |
| uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | |
| with: | |
| path: .git | |
| key: git-repo-upstream |