Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sync-upstream action #538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions actions/publish-image/sync-upstream/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Sync Upstream

on:
workflow_call:
inputs:
upstream-repo:
required: true
type: string
description: 'Upstream repository to sync from (format: owner/repo)'
branches:
required: true
type: string
description: 'JSON array of branches to sync'

jobs:
sync-branches:
runs-on: ubuntu-latest
permissions:
contents: write
statuses: write

strategy:
matrix:
branch: ${{ fromJSON(inputs.branches) }}
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git remote add upstream https://github.com/${{ inputs.upstream-repo }}.git
git fetch upstream ${{ matrix.branch }}

- name: Sync branch
run: |
git checkout -B ${{ matrix.branch }} upstream/${{ matrix.branch }}
git push -f origin ${{ matrix.branch }}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  - name: Load Secrets from Vault
    continue-on-error: false
    uses: rancher-eio/read-vault-secrets@main
    with:
      secrets: |
        secret/data/github/repo/${{ github.repository }}/github/app-credentials appId | APP_ID ;
        secret/data/github/repo/${{ github.repository }}/github/app-credentials privateKey | PRIVATE_KEY ;

  - name: Create App Token
    continue-on-error: false
    uses: actions/create-github-app-token@v1
    id: app-token
    with:
      app-id: ${{ env.APP_ID }}
      private-key: ${{ env.PRIVATE_KEY }}

- name: Update branch status
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      GH_TOKEN: ${{ steps.app-token.outputs.token }}

BRANCH: ${{ matrix.branch }}
run: |
SHA=$(git rev-parse HEAD)
gh api \
--method POST \
/repos/${{ github.repository }}/statuses/$SHA \
-f state=success \
-f description="Branch synced with upstream" \
-f context="Branch Sync Status"