-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): automatically add release version to Pongo
When a tag is created, this workflow would automatically create a PR on 'kong/kong-pongo' to add that version.
- Loading branch information
Showing
1 changed file
with
125 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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
name: Add New Release to Pongo | ||
|
||
on: | ||
push: | ||
tags: | ||
- '[1-9]+.[0-9]+.[0-9]+' | ||
|
||
jobs: | ||
set_vars: | ||
name: Set Vars | ||
runs-on: ubuntu-latest | ||
outputs: | ||
ce_ee: ${{ steps.define_vars.outputs.CE_EE }} | ||
tag_version: ${{ steps.define_vars.outputs.TAG_VERSION }} | ||
pr_branch: ${{ steps.define_vars.outputs.PR_BRANCH }} | ||
steps: | ||
- name: Define Vars | ||
id: define_vars | ||
shell: bash | ||
run: | | ||
if [[ "${GITHUB_REPOSITORY}" = "kong/kong" ]] ; then | ||
CE_EE=CE | ||
elif [[ "${GITHUB_REPOSITORY}" = "kong/kong-ee" ]] ; then | ||
CE_EE=EE | ||
fi | ||
echo "CE_EE=$CE_EE" >> "$GITHUB_OUTPUT" | ||
if [[ "${{ github.event_name }}" == "push" ]] ; then | ||
TAG_VERSION="${{ github.ref_name }}" | ||
elif [[ "${{ github.event_name }}" == "release" ]] ; then | ||
TAG_VERSION="${{ github.event.release.tag_name }}" | ||
fi | ||
echo "TAG_VERSION=$TAG_VERSION" >> "$GITHUB_OUTPUT" | ||
echo "PR_BRANCH=add-${CE_EE,,}-version-${TAG_VERSION}" >> "$GITHUB_OUTPUT" | ||
add_release_to_pongo: | ||
name: Add Release to Pongo | ||
runs-on: ubuntu-latest | ||
needs: | ||
- set_vars | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT }} | ||
steps: | ||
- name: Checkout Pongo | ||
id: checkout_pongo | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.PAT }} | ||
repository: kong/kong-pongo | ||
ref: master | ||
- name: Update Versions File | ||
id: update_versions_file | ||
shell: bash | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "GHA Bot" | ||
git checkout -b "${{ needs.set_vars.outputs.pr_branch }}" | ||
ce_ee="${{ needs.set_vars.outputs.ce_ee }}" | ||
VERSIONS_FILE="assets/kong_${ce_ee}_versions.ver" | ||
if [[ ! -f $VERSIONS_FILE ]]; then | ||
echo "Versions file '$VERSIONS_FILE' not found" | ||
exit 1 | ||
fi | ||
tag_version="${{ needs.set_vars.outputs.tag_version }}" | ||
echo "${tag_version}" >> "$VERSIONS_FILE" | ||
sort --version-sort -o "$VERSIONS_FILE" "$VERSIONS_FILE" | ||
git add "$VERSIONS_FILE" | ||
git commit -m "feat(version): add Kong ${ce_ee} version $tag_version" | ||
- name: Checkout Kong ${{ needs.set_vars.outputs.ce_ee }} | ||
id: checkout_kong | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.PAT }} | ||
ref: ${{ needs.set_vars.outputs.tag_version }} | ||
path: ${{ github.event.repository.name }} | ||
- name: Update Artifacts | ||
id: update_artifacts | ||
shell: bash | ||
run: | | ||
repo_name=${{ github.event.repository.name }} | ||
tag_version="${{ needs.set_vars.outputs.tag_version }}" | ||
mkdir -p "kong-versions/${tag_version}/kong" | ||
cp "${repo_name}/Makefile" "kong-versions/${tag_version}/kong/" | ||
cp -R "${repo_name}/bin" "kong-versions/${tag_version}/kong/" | ||
mkdir -p "kong-versions/${tag_version}/kong/spec" | ||
for fname in ${repo_name}/spec/* ; do | ||
case $fname in | ||
(${repo_name}/spec/[0-9]*) | ||
# skip test files | ||
;; | ||
(*) | ||
cp -R "$fname" "kong-versions/${tag_version}/kong/spec/" | ||
;; | ||
esac | ||
done | ||
if [[ -d "${repo_name}/spec-ee" ]] ; then | ||
mkdir -p "kong-versions/${tag_version}/kong/spec-ee" | ||
for fname in ${repo_name}/spec-ee/* ; do | ||
case $fname in | ||
(${repo_name}/spec-ee/[0-9]*) | ||
# skip test files | ||
;; | ||
(*) | ||
cp -R "$fname" "kong-versions/${tag_version}/kong/spec-ee/" | ||
;; | ||
esac | ||
done | ||
fi | ||
rm -rf "${repo_name}" | ||
git add kong-versions/ | ||
git commit -m "chore(version): add Kong "${{ needs.set_vars.outputs.ce_ee }}" version $tag_version artifacts" | ||
- name: Create PR | ||
id: create_pr | ||
shell: bash | ||
run: | | ||
git push -u origin ${{ needs.set_vars.outputs.pr_branch }} | ||
gh pr create -B master -H "${{ needs.set_vars.outputs.pr_branch }}" --title "Add Kong "${{ needs.set_vars.outputs.ce_ee }}" version ${{ needs.set_vars.outputs.tag_version }}" --body 'Created by GHA Bot.' |