-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI: add workflow to sync master to current automatically (#77)
Signed-off-by: Jinzhe Zeng <[email protected]>
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.git_archival.txt export-subst | ||
# different in different branches | ||
.nvmrc merge=ours |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Sync master to current | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: write | ||
|
||
jobs: | ||
pr: | ||
name: Submit PR | ||
runs-on: ubuntu-latest | ||
env: | ||
target_branch: current | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ env.target_branch }} | ||
fetch-depth: 0 | ||
- name: Create PR | ||
run: | | ||
git config user.name "github-actions[bot]" | ||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
git branch ${BRANCH_NAME} -f | ||
git checkout ${BRANCH_NAME} | ||
git config --global merge.ours.driver true | ||
# sync .gitattributes first | ||
git checkout origin/${{ github.ref_name }} -- .gitattributes | ||
git add .gitattributes | ||
if git diff-index --quiet HEAD --; then | ||
echo "No changes to commit." | ||
else | ||
git commit -m "Sync .gitattributes from ${{ github.ref_name }}" | ||
fi | ||
git merge origin/${{ github.ref_name }} | ||
git push origin ${BRANCH_NAME} --force | ||
PR_URL="$(gh pr list --head "${BRANCH_NAME}" --state open --json url --jq .[].url)" | ||
if [[ -n "${PR_URL}" ]]; then | ||
echo "PR already exists -> ${PR_URL}" | ||
exit 0 | ||
else | ||
gh pr create --title "Sync ${{ github.ref_name }} to ${{ env.target_branch }}" --body "Generated by GitHub Actions" --base ${{ env.target_branch }} -r njzjz -a njzjz | ||
fi | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
BRANCH_NAME: sync-branches/${{ github.ref_name }}-to-${{ env.target_branch }} |