-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace mermaid commit rendering with a table
- Loading branch information
kendal
committed
Jul 16, 2024
1 parent
cf2e052
commit 0e3d880
Showing
1 changed file
with
80 additions
and
79 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,79 +1,80 @@ | ||
name: Sync Fork | ||
description: Rebase a forked repository's branch on top of an upstream repository's branch. | ||
author: The Browser Company | ||
|
||
inputs: | ||
fork_repo: | ||
description: The repository to update. | ||
required: false | ||
|
||
fork_branch: | ||
description: The branch to update. | ||
required: true | ||
|
||
upstream_repo: | ||
description: The repository to pull changes from. | ||
required: true | ||
|
||
upstream_branch: | ||
description: The branch to pull changes from. | ||
required: true | ||
|
||
upstream_host: | ||
description: The upstream repository URL host, if not github.com. | ||
required: false | ||
default: 'github.com' | ||
|
||
dry_run: | ||
description: If true, changes are not pushed to the fork. | ||
required: false | ||
default: false | ||
|
||
token: | ||
description: Authentication token to use for Git commands | ||
required: false | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ inputs.fork_repo }} | ||
ref: ${{ inputs.fork_branch }} | ||
# Fetch all commits from the fork to prevent arbitrary merge conflicts. | ||
fetch-depth: 0 | ||
path: ${{ github.workspace }}/fork | ||
token: ${{ inputs.token || github.token }} | ||
|
||
- name: Rebase onto upstream | ||
shell: pwsh | ||
run: | | ||
Set-StrictMode -Version 1 | ||
cd ${{ github.workspace }}/fork | ||
git config --global user.name '${{ github.actor }}' | ||
git config --global user.email '${{ github.actor }}@users.noreply.github.com' | ||
git remote add upstream https://${{ inputs.upstream_host }}/${{ inputs.upstream_repo }} | ||
git fetch upstream ${{ inputs.upstream_branch }} | ||
# Store the list of commits we're about to rebase as a job summary: | ||
$NewCommitsFromUpstream=(git log --format="[%h] %s" --no-merges upstream/${{ inputs.upstream_branch }} ^${{ inputs.fork_branch }}) | ||
echo "``````mermaid" | Out-File -Append -Encoding utf8 $env:GITHUB_STEP_SUMMARY | ||
echo "%%{init: { 'theme': 'default', 'gitGraph': { 'mainBranchName': '${{ inputs.upstream_repo}}/${{ inputs.upstream_branch }}', 'rotateCommitLabel': false}} }%%" | Out-File -Append -Encoding utf8 $env:GITHUB_STEP_SUMMARY | ||
echo "gitGraph TB:" | Out-File -Append -Encoding utf8 $env:GITHUB_STEP_SUMMARY | ||
foreach ($Commit in $NewCommitsFromUpstream) { | ||
$Commit=$Commit -replace "`"","'" | ||
echo "commit id: `"${Commit}`"" | Out-File -Append -Encoding utf8 $env:GITHUB_STEP_SUMMARY | ||
} | ||
echo "``````" | Out-File -Append -Encoding utf8 $env:GITHUB_STEP_SUMMARY | ||
git checkout ${{ inputs.fork_branch }} | ||
git rebase upstream/${{ inputs.upstream_branch }} | ||
- name: Push changes | ||
if: ${{ inputs.dry_run == 'false' || inputs.dry_run == false }} | ||
shell: pwsh | ||
run: git -C ${{ github.workspace }}/fork push origin ${{ inputs.fork_branch }} -f | ||
|
||
name: Sync Fork | ||
description: Rebase a forked repository's branch on top of an upstream repository's branch. | ||
author: The Browser Company | ||
|
||
inputs: | ||
fork_repo: | ||
description: The repository to update. | ||
required: false | ||
|
||
fork_branch: | ||
description: The branch to update. | ||
required: true | ||
|
||
upstream_repo: | ||
description: The repository to pull changes from. | ||
required: true | ||
|
||
upstream_branch: | ||
description: The branch to pull changes from. | ||
required: true | ||
|
||
upstream_host: | ||
description: The upstream repository URL host, if not github.com. | ||
required: false | ||
default: 'github.com' | ||
|
||
dry_run: | ||
description: If true, changes are not pushed to the fork. | ||
required: false | ||
default: false | ||
|
||
token: | ||
description: Authentication token to use for Git commands | ||
required: false | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ inputs.fork_repo }} | ||
ref: ${{ inputs.fork_branch }} | ||
# Fetch all commits from the fork to prevent arbitrary merge conflicts. | ||
fetch-depth: 0 | ||
path: ${{ github.workspace }}/fork | ||
token: ${{ inputs.token || github.token }} | ||
|
||
- name: Rebase onto upstream | ||
shell: pwsh | ||
run: | | ||
Set-StrictMode -Version 1 | ||
cd ${{ github.workspace }}/fork | ||
git config --global user.name '${{ github.actor }}' | ||
git config --global user.email '${{ github.actor }}@users.noreply.github.com' | ||
git remote add upstream https://${{ inputs.upstream_host }}/${{ inputs.upstream_repo }} | ||
git fetch upstream ${{ inputs.upstream_branch }} | ||
# Store the list of commits we're about to rebase as a job summary. | ||
# --format is a GitHub flavored markdown table row. | ||
$NewCommitsFromUpstream=(git log --format="|%h|%s|" --no-merges upstream/${{ inputs.upstream_branch }} ^${{ inputs.fork_branch }}) | ||
echo "|Commit|Description|" | Out-File -Append -Encoding utf8 $env:GITHUB_STEP_SUMMARY | ||
echo "|:-----|:----------|" | Out-File -Append -Encoding utf8 $env:GITHUB_STEP_SUMMARY | ||
foreach ($Commit in $NewCommitsFromUpstream) { | ||
$Commit=$Commit -replace "`"","'" | ||
echo "${Commit}" | Out-File -Append -Encoding utf8 $env:GITHUB_STEP_SUMMARY | ||
} | ||
git checkout ${{ inputs.fork_branch }} | ||
git rebase upstream/${{ inputs.upstream_branch }} | ||
- name: Push changes | ||
if: ${{ inputs.dry_run == 'false' || inputs.dry_run == false }} | ||
shell: pwsh | ||
run: git -C ${{ github.workspace }}/fork push origin ${{ inputs.fork_branch }} -f | ||
|