Skip to content

Commit 3b3e7cd

Browse files
lukidzislonkabartsmykla
authored andcommitted
chore(gha): add synchronisation action for keep fork in sync
added instruction about conflict resolution Signed-off-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Krzysztof Słonka <[email protected]> Co-authored-by: Bart Smykla <[email protected]>
1 parent 79c535b commit 3b3e7cd

File tree

3 files changed

+235
-0
lines changed

3 files changed

+235
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
current_tag=$(git tag --list 'v[0-9].[0-9]*.[0-9]*' --merged origin/release --sort=-creatordate | head -n 1)
4+
main_tag=$(git tag --list 'v[0-9].[0-9]*.[0-9]*' --merged origin/main --sort=-creatordate | head -n 1)
5+
6+
# Remove the prefix `v` and `+kong-*` suffix for comparison
7+
released_tag="${current_tag%+kong-*}"
8+
currentVersion="${released_tag#v}"
9+
10+
# The main branch won't have +kong-* suffix
11+
newVersion="${main_tag#v}"
12+
13+
echo "Current release tag prefix: $released_tag"
14+
echo "Upstream tag: $main_tag"
15+
new_tag="${main_tag}+kong-1"
16+
if [[ $current_tag != $new_tag ]]; then
17+
echo "New tag: $new_tag"
18+
else
19+
echo "Tags are equal, no need to release"
20+
exit 0
21+
fi
22+
23+
# Convert versions to arrays
24+
IFS='.' read -r -a currentParts <<< "$currentVersion"
25+
IFS='.' read -r -a newParts <<< "$newVersion"
26+
27+
echo "released_tag=$released_tag" >> $GITHUB_OUTPUT
28+
echo "main_tag=$main_tag" >> $GITHUB_OUTPUT
29+
30+
echo "Current base tag: $currentVersion"
31+
echo "Upstream tag: $newVersion"
32+
33+
# Compare each part
34+
for i in 0 1 2; do
35+
if [[ ${newParts[i]:-0} -gt ${currentParts[i]:-0} ]]; then
36+
echo "The new tag is higher."
37+
echo "New version tag: $new_tag"
38+
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
39+
exit 0
40+
elif [[ ${newParts[i]:-0} -lt ${currentParts[i]:-0} ]]; then
41+
echo "The current tag is higher. That shouldn't be that case, please fix tagging."
42+
exit 1
43+
fi
44+
done
45+
46+
echo "The tags are equal."
47+
exit 0
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: 'Sync with Upstream'
2+
3+
on:
4+
schedule:
5+
- cron: '0 6 * * *'
6+
#scheduled at 06:00 everyday
7+
workflow_dispatch: {}
8+
9+
permissions:
10+
actions: write
11+
contents: write
12+
13+
env:
14+
GH_USER: "github-actions[bot]"
15+
GH_EMAIL: "<41898282+github-actions[bot]@users.noreply.github.com>"
16+
17+
jobs:
18+
sync-with-upstream-main:
19+
runs-on: ubuntu-latest
20+
name: Sync with upstream main
21+
steps:
22+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
23+
with:
24+
fetch-depth: 0
25+
persist-credentials: false
26+
- name: Generate GitHub app token
27+
id: github-app-token
28+
uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
29+
with:
30+
app-id: ${{ secrets.APP_ID }}
31+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
32+
- name: Sync upstream changes
33+
id: sync
34+
uses: aormsby/[email protected]
35+
with:
36+
git_config_user: ${{ env.GH_USER }}
37+
git_config_email: ${{ env.GH_EMAIL }}
38+
target_sync_branch: main
39+
target_repo_token: ${{ steps.github-app-token.outputs.token }}
40+
target_branch_push_args: "-f --tags"
41+
upstream_sync_branch: main
42+
upstream_sync_repo: envoyproxy/go-control-plane
43+
upstream_pull_args: "--tags"
44+
test_mode: false
45+
git_config_pull_rebase: true
46+
- name: New commits found
47+
if: steps.sync.outputs.has_new_commits == 'true'
48+
run: echo "New commits were found to sync."
49+
- name: No new commits
50+
if: steps.sync.outputs.has_new_commits == 'false'
51+
run: echo "There were no new commits."
52+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
53+
if: steps.sync.outputs.has_new_commits == 'true'
54+
with:
55+
fetch-depth: 0
56+
- name: Get new version tag
57+
id: new-version-tag
58+
if: steps.sync.outputs.has_new_commits == 'true'
59+
shell: bash
60+
run: ".github/scripts/get-version-tags.sh"
61+
- name: Print tags
62+
if: steps.sync.outputs.has_new_commits == 'true'
63+
run: |
64+
echo "Current fork tag: ${{ steps.new-version-tag.outputs.released_tag }}"
65+
echo "Newest upstream tag: ${{ steps.new-version-tag.outputs.main_tag }}"
66+
echo "New fork release tag: ${{ steps.new-version-tag.outputs.new_tag }}"
67+
- name: Release new version
68+
if: steps.new-version-tag.outputs.released_tag != steps.new-version-tag.outputs.main_tag
69+
run: |
70+
git remote -v
71+
git remote set-url origin https://${{ steps.github-app-token.outputs.token }}@github.com/kumahq/go-control-plane.git
72+
git config user.name "${GH_USER}"
73+
git config user.email "${GH_EMAIL}"
74+
git checkout release
75+
git pull
76+
git rebase --onto ${{ steps.new-version-tag.outputs.main_tag }} ${{ steps.new-version-tag.outputs.released_tag }} release
77+
git tag ${{ steps.new-version-tag.outputs.new_tag }}
78+
git push origin release --tags --force-with-lease

DEVELOPMENT.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# go-control-plane Fork
2+
3+
This is a fork of [go-control-plane](https://github.com/envoyproxy/go-control-plane). Before introducing any changes here, please create an issue or submit a change to the upstream repository, as it might impact other users
4+
5+
## How to Contribute
6+
7+
In this fork, we maintain two branches:
8+
9+
- `main`: This branch is synced daily with the upstream repository via an automated action. The only custom addition is the job responsible for synchronization
10+
- `release`: This branch contains all user-introduced changes. It diverges from the stable version to ensure no unreleased commits are included. Any changes you make should target this branch
11+
12+
## Steps to Contribute
13+
14+
1. Check out the `release` branch
15+
2. Make your changes and create a pull request targeting the `release` branch
16+
3. Once your pull request is reviewed, merge it into the `release` branch
17+
18+
## Releasing
19+
20+
For standard releases, the `Sync with Upstream` action handles synchronization and creates custom versions whenever there’s a new upstream release. We fetch upstream tags, so, for example, `v0.13.1` in this fork corresponds directly to the same version in the upstream repository
21+
22+
Our job appends a custom suffix (`+kong-1`) to the upstream tag. If you merge a change and want to create a release, you should tag your commit using the following pattern:
23+
24+
```text
25+
<current-version>+kong-<incremented-number>
26+
```
27+
28+
### Why use `+` instead of `-`?
29+
30+
- Per Semantic Versioning (https://semver.org/), anything after a hyphen (`-`) denotes a pre-release (e.g., `1.2.3-alpha.1`). Many tooling ecosystems interpret pre-releases as being "behind" the final release and will constantly flag that a newer non-pre-release version is available
31+
- Anything after a plus (`+`) is build metadata. Build metadata does not affect version precedence. By using tags like `vX.Y.Z+kong-N`, we keep the base version identical to upstream and attach our fork-specific identifier without triggering dependency updaters to suggest moving to plain `vX.Y.Z`
32+
33+
#### Example
34+
35+
The current tag is `v0.13.1+kong-1`. After merging your changes, you want to release a new version. You should tag your commit as:
36+
37+
`v0.13.1+kong-2`
38+
39+
After tagging, push the commit to the repository to finalize the release.
40+
41+
## Conflict resolution
42+
43+
It might happen that the automatic release job can hit a conflict. In this situation the maintainer needs to resolve this manually
44+
45+
### Instruction
46+
47+
1. Fetch current `main` and `release` branch
48+
49+
```bash
50+
git fetch origin --tags
51+
```
52+
53+
2. Update the current main branch with origin
54+
55+
```bash
56+
git reset --hard origin/main
57+
```
58+
59+
3. Change to the release branch
60+
61+
```bash
62+
git checkout release
63+
git reset --hard origin/release
64+
```
65+
66+
4. Remove Untracked files and directories
67+
68+
```bash
69+
git clean -fd
70+
```
71+
72+
5. Get the new tag value
73+
74+
```bash
75+
./.github/scripts/get-version-tags.sh
76+
```
77+
78+
**Output:**
79+
80+
```bash
81+
Current release tag prefix: v0.13.1
82+
Upstream tag: v0.13.2
83+
New tag: v0.13.2+kong-1
84+
```
85+
86+
if tags are equal, you are going to see message `"Tags are equal, no need to release"` and you don't need to release/rebase anything
87+
88+
6. Rebase release branch between tags:
89+
90+
```bash
91+
git rebase --onto "<upstream-tag>" <current-release-tag-prefix> release
92+
```
93+
94+
7. If you encounter git conflicts, resolve them, and follow git instruction
95+
96+
- resolve conflicts
97+
- `git add <files>`
98+
- `git rebase --continue`
99+
100+
8. Tag the commit
101+
102+
```bash
103+
git tag "<new-tag>"
104+
```
105+
106+
9. Push changes to origin
107+
108+
```bash
109+
git push origin release --tags --force-with-lease
110+
```

0 commit comments

Comments
 (0)