Skip to content

Commit 2621087

Browse files
authored
Update LTS github actions (gloo-v1.6.x) (#152)
* Update LTS github actions * re-introduce PR GHA
1 parent e179391 commit 2621087

File tree

4 files changed

+146
-3
lines changed

4 files changed

+146
-3
lines changed

.github/workflows/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# GitHub Workflows
2+
3+
# Syncing LTS Branches
4+
5+
Solo-Apis is a public, read-only mirror for API definitions. In order to keep API definitions in sync, we automate the process of syncing long term support (LTS) branches.
6+
7+
To keep the LTS branches unique, we prefix them with the name of the owner repo. For example, in gloo-edge the `1.8.x` LTS branch is tracked by the `gloo-1.8.x` LTS branch in solo-apis.
8+
9+
#### How do Gloo Edge APIs get synced?
10+
11+
1. A Gloo release occurs (ie v1.8.1 is released from LTS branch v1.8.x)
12+
1. A Gloo GHA generates the new APIs and pushes those to a branch (ie sync-apis/gloo-v1.8.x/gloo-v1.8.1)
13+
1. A [Solo-Apis GHA](#create-pr-for-lts-branch) notices that a commit was pushed to a `sync-apis` prefixed branch, and creates a PR.
14+
1. That PR is manually reviewed by a developer, and eventually approved
15+
1. A [Solo-Apis GHA](#tag-commit-on-lts-branch) notices that a commit is pushed to a LTS branch (ie gloo-v1.8.x) and tags the commit. This tag is referenced by other repositories.
16+
17+
The GitHub actions that enable this process are defined below:
18+
19+
## Create PR for LTS Branch
20+
21+
The repo that owns API definitions is responsible for deciding when to update API definitions (ie after a release) and pushing the new API to a branch in solo-apis.
22+
23+
This action only needs to know 2 pieces of information:
24+
1. The name of the LTS branch it should merge the code into
25+
1. The tag that should be applied to the merge commit
26+
27+
We decided to use the branch name to pass this information. The workflow only operates on branches in the following format:
28+
```sync-apis/{LTS_BRANCH_NAME}/{LTS_TAG_NAME}```
29+
30+
This allows the workflow to operate successfully, knowing the least information possible about the source repo that triggered the sync.
31+
32+
The workflow has 2 responsibilities:
33+
1. To open a pull request to the LTS branch name
34+
1. To signify the tag that should be applied, when the PR merges
35+
36+
The first step is easy, since the LTS branch is extracted from the branch name.
37+
The second step is more challenging since after the PR merges, the GitHub event that is triggered does not contain a reference to the name of the branch that merged. Therefore, we don't have a way to determine the name of the tag to apply. **We use a little trick to resolve this: providing a commit message with the tag included, and then extracting that commit message when generating a tag name.**
38+
39+
40+
*Note: This workflow opens a PR, but expects manual intervention by an engineer to approve the PR*
41+
42+
## Tag Commit on LTS Branch
43+
44+
After PRs are merged into LTS branches, we:
45+
1. Extract the latest commit message (which the above workflow provided)
46+
1. Determine the tag name from the commit message
47+
1. Push a tag name for that commit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Create PR for LTS Branch
2+
on:
3+
push:
4+
branches:
5+
- 'sync-apis/**/**'
6+
7+
jobs:
8+
create-pr-for-api-sync-branches:
9+
runs-on: ubuntu-18.04
10+
steps:
11+
- name: Cancel Previous Actions
12+
uses: styfle/[email protected]
13+
with:
14+
access_token: ${{ github.token }}
15+
- name: Checkout Branch
16+
uses: actions/checkout@v2
17+
- name: Parse GitHub Ref
18+
id: parse_github_ref
19+
env:
20+
DELIMITER: "/"
21+
DEST_BRANCH_FIELD_NUMBER: 2
22+
TAG_NAME_FIELD_NUMBER: 3
23+
REF: ${{ github.ref }}
24+
IGNORE_REF_PREFIX: 'refs/heads/'
25+
run: |
26+
echo "REF: $REF"
27+
28+
GITHUB_BRANCH_NAME=${REF#"$IGNORE_REF_PREFIX"}
29+
echo "GITHUB_BRANCH_NAME: $GITHUB_BRANCH_NAME"
30+
31+
DESTINATION_BRANCH=$(echo $GITHUB_BRANCH_NAME | cut -f $DEST_BRANCH_FIELD_NUMBER -d $DELIMITER )
32+
TAG_NAME=$(echo $GITHUB_BRANCH_NAME | cut -f $TAG_NAME_FIELD_NUMBER -d $DELIMITER )
33+
34+
echo "::set-output name=destination_branch::$(echo $DESTINATION_BRANCH )"
35+
echo "::set-output name=tag_name::$(echo $TAG_NAME )"
36+
- name: Setup Git
37+
env:
38+
GIT_USER_NAME: soloio-bot
39+
GIT_USER_EMAIL: [email protected]
40+
run: |
41+
git config user.name $GIT_USER_NAME
42+
git config user.email $GIT_USER_EMAIL
43+
- name: Ensure LTS Branch Exists
44+
env:
45+
BRANCH: ${{ steps.parse_github_ref.outputs.destination_branch }}
46+
run: |
47+
git fetch origin
48+
BRANCH_EXISTS=$(git ls-remote --heads origin $BRANCH)
49+
50+
if [[ -z ${BRANCH_EXISTS} ]]; then
51+
echo "$BRANCH does not exist, creating it"
52+
git push origin "HEAD:$BRANCH"
53+
else
54+
echo "$BRANCH exists, nothing to do"
55+
fi
56+
- name: Create Pull Request
57+
uses: repo-sync/pull-request@v2
58+
with:
59+
destination_branch: ${{ steps.parse_github_ref.outputs.destination_branch }}
60+
pr_reviewer: "solo-apis/solo-apis"
61+
pr_label: "auto-pr"
62+
pr_allow_empty: true
63+
github_token: ${{ secrets.SOLO_BOT_REPO_SECRET }}
64+
pr_title: "Sync APIs. @tag-name=${{ steps.parse_github_ref.outputs.tag_name }}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Tag Commit on LTS Branch
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- 'gloo-master'
7+
- 'gloo-v**.**.x'
8+
jobs:
9+
tag-version:
10+
runs-on: ubuntu-latest
11+
env:
12+
# The regex of a commit produced by the soloio-bot
13+
COMMIT_REGEX: "^.*(Sync APIs.)+.*$"
14+
steps:
15+
- name: Cancel Previous Actions
16+
uses: styfle/[email protected]
17+
with:
18+
access_token: ${{ github.token }}
19+
- uses: actions/checkout@v2
20+
with:
21+
fetch-depth: '0'
22+
- name: Parse out tag name from commit message
23+
id: tag_version
24+
run: |
25+
if [[ $(git log -1 --oneline) =~ ${{ env.COMMIT_REGEX }} ]]; then
26+
TAG_NAME=$(git log -1 --oneline | awk -F'@tag-name=' '{print $2}' | awk -F' ' '{print $1}')
27+
fi
28+
echo "::set-output name=tag_name::$(echo $TAG_NAME)"
29+
- name: Bump version and push tag
30+
if: steps.tag_version.outputs.tag_name != ''
31+
uses: anothrNick/[email protected]
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
CUSTOM_TAG: ${{ steps.tag_version.outputs.tag_name }}
35+
RELEASE_BRANCHES: '*master,gloo-**.**.x'

.github/workflows/pull_request.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: pull_request
22

33
on:
4-
push:
5-
branches:
6-
- 'master'
74
pull_request:
85

96
jobs:

0 commit comments

Comments
 (0)