-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow to release webhook in rancher/charts and rancher/rancher
- Loading branch information
Showing
5 changed files
with
316 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,74 @@ | ||
name: Bump Webhook RC against rancher/charts | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
charts_ref: | ||
description: "Submit PR against the following rancher/charts branch (eg: dev-v2.9)" | ||
required: true | ||
default: "dev-v2.9" | ||
prev_webhook: | ||
description: "Previous Webhook version (eg: 0.5.0-rc13)" | ||
required: true | ||
default: "" | ||
new_webhook: | ||
description: "New Webhook version (eg: 0.5.0-rc14)" | ||
required: true | ||
default: "" | ||
|
||
env: | ||
CHARTS_REF: ${{ github.event.inputs.charts_ref }} | ||
PREV_WEBHOOK: ${{ github.event.inputs.prev_webhook }} | ||
NEW_WEBHOOK: ${{ github.event.inputs.new_webhook }} | ||
|
||
jobs: | ||
create-rancher-charts-pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.inputs.ref }} | ||
path: webhook | ||
|
||
# Checkout the fork first because it's simpler to setup the token for the | ||
# push later on | ||
- name: Checkout fork of rancher/charts | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
repository: tomleb/rancher-charts | ||
token: ${{ secrets.PUSH_TO_FORKS_TOKEN }} | ||
path: charts | ||
|
||
- name: Install dependencies | ||
run: sudo snap install yq --channel=v4/stable | ||
|
||
- name: Setup repo dir | ||
run: | | ||
cd charts | ||
BRANCH="gha-test-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" | ||
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "tomleb webhook Bot" | ||
git remote add upstream https://github.com/rancher/charts | ||
git fetch upstream | ||
git checkout -b $BRANCH "upstream/$CHARTS_REF" | ||
- name: Run release script | ||
run: | | ||
./webhook/.github/workflows/scripts/release-against-charts.sh charts "$PREV_WEBHOOK" "$NEW_WEBHOOK" | ||
- name: Push and create pull request | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PUSH_TO_FORKS_TOKEN }} | ||
run: | | ||
cd charts | ||
git push origin $BRANCH | ||
body=$(../webhook/.github/workflows/scripts/release-message.sh "$PREV_WEBHOOK" "$NEW_WEBHOOK") | ||
gh pr create \ | ||
--title "[$CHARTS_REF] Bump rancher-webhook to v$NEW_WEBHOOK" \ | ||
--body "$body" \ | ||
--repo rancher/charts \ | ||
--head "tomleb:$BRANCH" \ | ||
--base "$CHARTS_REF" |
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,74 @@ | ||
name: Bump Webhook RC against rancher/rancher | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
rancher_ref: | ||
description: "Submit PR against the following rancher/charts branch (eg: dev-v2.9)" | ||
required: true | ||
default: "release/v2.9" | ||
prev_webhook: | ||
description: "Previous Webhook version (eg: 0.5.0-rc13)" | ||
required: true | ||
default: "" | ||
new_webhook: | ||
description: "New Webhook version (eg: 0.5.0-rc14)" | ||
required: true | ||
default: "" | ||
|
||
env: | ||
RANCHER_REF: ${{ github.event.inputs.rancher_ref }} | ||
PREV_WEBHOOK: ${{ github.event.inputs.prev_webhook }} | ||
NEW_WEBHOOK: ${{ github.event.inputs.new_webhook }} | ||
|
||
jobs: | ||
create-rancher-charts-pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.inputs.ref }} | ||
path: webhook | ||
|
||
# Checkout the fork first because it's simpler to setup the token for the | ||
# push later on | ||
- name: Checkout fork of rancher/rancher | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
repository: tomleb/rancher-rancher | ||
token: ${{ secrets.PUSH_TO_FORKS_TOKEN }} | ||
path: rancher | ||
|
||
- name: Install dependencies | ||
run: sudo snap install yq --channel=v4/stable | ||
|
||
- name: Setup repo dir | ||
run: | | ||
cd rancher | ||
BRANCH="gha-test-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" | ||
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "tomleb webhook Bot" | ||
git remote add upstream https://github.com/rancher/rancher | ||
git fetch upstream | ||
git checkout -b $BRANCH "upstream/$RANCHER_REF" | ||
- name: Run release script | ||
run: | | ||
./webhook/.github/workflows/scripts/release-against-rancher.sh rancher "$NEW_WEBHOOK" | ||
- name: Push and create pull request | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PUSH_TO_FORKS_TOKEN }} | ||
run: | | ||
cd rancher | ||
git push origin $BRANCH | ||
body=$(../webhook/.github/workflows/scripts/release-message.sh "$PREV_WEBHOOK" "$NEW_WEBHOOK") | ||
gh pr create \ | ||
--title "[$RANCHER_REF] Bump rancher-webhook to v$NEW_WEBHOOK" \ | ||
--body "$body" \ | ||
--repo rancher/rancher \ | ||
--head "tomleb:$BRANCH" \ | ||
--base "$RANCHER_REF" |
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,65 @@ | ||
#!/bin/bash | ||
# | ||
# Bumps Webhook version in a locally checked out rancher/charts repository | ||
# | ||
# Usage: | ||
# ./release-against-charts.sh <path to charts repo> <prev webhook release> <new webhook release> | ||
# | ||
# Example: | ||
# ./release-against-charts.sh "${GITHUB_WORKSPACE}" "0.5.0-rc13" "0.5.0-rc14" | ||
|
||
CHARTS_DIR=$1 | ||
PREV_WEBHOOK_VERSION=$2 # e.g. 0.5.2-rc.3 | ||
NEW_WEBHOOK_VERSION=$3 | ||
|
||
usage() { | ||
cat <<EOF | ||
Usage: | ||
$0 <path to charts repo> <prev webhook release> <new webhook release> | ||
EOF | ||
} | ||
|
||
if [ -z "$CHARTS_DIR" ] || [ -z "$PREV_WEBHOOK_VERSION" ] || [ -z "$NEW_WEBHOOK_VERSION" ]; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
set -ue | ||
|
||
pushd "${CHARTS_DIR}" > /dev/null | ||
|
||
# Validate the given webhook version (eg: 0.5.0-rc.13) | ||
if ! grep -q "${PREV_WEBHOOK_VERSION}" ./packages/rancher-webhook/package.yaml; then | ||
echo "Previous Webhook version references do not exist in ./packages/rancher-webhook/. The content of the file is:" | ||
cat ./packages/rancher-webhook/package.yaml | ||
exit 1 | ||
fi | ||
|
||
# Get the chart version (eg: 104.0.0) | ||
if ! PREV_CHART_VERSION=$(yq '.version' ./packages/rancher-webhook/package.yaml); then | ||
echo "Unable to get chart version from ./packages/rancher-webhook/package.yaml. The content of the file is:" | ||
cat ./packages/rancher-webhook/package.yaml | ||
exit 1 | ||
fi | ||
NEW_CHART_VERSION=$PREV_CHART_VERSION | ||
|
||
sed -i "s/${PREV_WEBHOOK_VERSION}/${NEW_WEBHOOK_VERSION}/g" ./packages/rancher-webhook/package.yaml | ||
|
||
git add packages/rancher-webhook | ||
git commit -m "Bump rancher-webhook to v$NEW_WEBHOOK_VERSION" | ||
|
||
PACKAGE=rancher-webhook make charts | ||
git add ./assets/rancher-webhook ./charts/rancher-webhook | ||
git commit -m "make charts" | ||
|
||
CHART=rancher-webhook VERSION=${PREV_CHART_VERSION}+up${PREV_WEBHOOK_VERSION} make remove | ||
git add ./assets/rancher-webhook ./charts/rancher-webhook ./index.yaml | ||
git commit -m "make remove" | ||
|
||
yq --inplace "del(.rancher-webhook.[] | select(. == \"${PREV_CHART_VERSION}+up${PREV_WEBHOOK_VERSION}\"))" release.yaml | ||
yq --inplace ".rancher-webhook += [\"${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION}\"]" release.yaml | ||
|
||
git add release.yaml | ||
git commit -m "Add rancher-webhook ${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION} to release.yaml" | ||
|
||
popd > /dev/null |
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,56 @@ | ||
#!/bin/bash | ||
# | ||
# Bumps Webhook version in a locally checked out rancher/rancher repository | ||
# | ||
# Usage: | ||
# ./release-against-rancher.sh <path to rancher repo> <new webhook release> | ||
# | ||
# Example: | ||
# ./release-against-charts.sh "${GITHUB_WORKSPACE}" "0.5.0-rc14" | ||
|
||
RANCHER_DIR=$1 | ||
NEW_WEBHOOK_VERSION=$2 # e.g. 0.5.2-rc.3 | ||
|
||
usage() { | ||
cat <<EOF | ||
Usage: | ||
$0 <path to rancher repo> <new webhook release> | ||
EOF | ||
} | ||
|
||
if [ -z "$RANCHER_DIR" ] || [ -z "$NEW_WEBHOOK_VERSION" ]; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
set -ue | ||
|
||
pushd "${RANCHER_DIR}" > /dev/null | ||
|
||
# Validate the given webhook version (eg: 0.5.0-rc.13) | ||
if grep -q "${NEW_WEBHOOK_VERSION}" ./build.yaml; then | ||
echo "build.yaml already at version v${NEW_WEBHOOK_VERSION}" | ||
exit 1 | ||
fi | ||
|
||
# Get the chart version (eg: 104.0.0) | ||
if ! PREV_CHART_VERSION=$(yq -r '.webhookVersion' ./build.yaml | cut -d+ -f1); then | ||
echo "Unable to get chart version from ./build.yaml. The content of the file is:" | ||
cat ./build.yaml | ||
exit 1 | ||
fi | ||
NEW_CHART_VERSION=$PREV_CHART_VERSION | ||
|
||
yq --inplace ".webhookVersion = \"${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION}\"" ./build.yaml | ||
|
||
# Downloads dapper | ||
make .dapper | ||
|
||
# DAPPER_MODE=bind will make sure we output everything that changed | ||
DAPPER_MODE=bind ./.dapper go generate ./... || true | ||
DAPPER_MODE=bind ./.dapper rm -rf go | ||
|
||
git add . | ||
git commit -m "Bump webhook to ${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION}" | ||
|
||
popd > /dev/null |
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,47 @@ | ||
#!/bin/sh | ||
|
||
PREV_WEBHOOK_VERSION=$1 # e.g. 0.5.2-rc.3 | ||
NEW_WEBHOOK_VERSION=$2 | ||
GITHUB_TRIGGERING_ACTOR=${GITHUB_TRIGGERING_ACTOR:-} | ||
|
||
usage() { | ||
cat <<EOF | ||
Usage: | ||
$0 <prev webhook release> <new webhook release> | ||
EOF | ||
} | ||
|
||
if [ -z "$PREV_WEBHOOK_VERSION" ] || [ -z "$NEW_WEBHOOK_VERSION" ]; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
set -ue | ||
|
||
# XXX: That's wasteful but doing it by caching the response in a var was giving | ||
# me unicode error. | ||
url=$(gh release view --repo rancher/webhook --json url "v${NEW_WEBHOOK_VERSION}" --jq '.url') | ||
body=$(gh release view --repo rancher/webhook --json body "v${NEW_WEBHOOK_VERSION}" --jq '.body') | ||
|
||
generated_by="" | ||
if [ -n "$GITHUB_TRIGGERING_ACTOR" ]; then | ||
generated_by=$(cat <<EOF | ||
# About this PR | ||
The workflow was triggered by $GITHUB_TRIGGERING_ACTOR. | ||
EOF | ||
) | ||
fi | ||
|
||
cat <<EOF | ||
# Release note for [v${NEW_WEBHOOK_VERSION}]($url) | ||
$body | ||
# Useful links | ||
- Commit comparison: https://github.com/rancher/webhook/compare/v${PREV_WEBHOOK_VERSION}...v${NEW_WEBHOOK_VERSION} | ||
- Release v${PREV_WEBHOOK_VERSION}: https://github.com/rancher/webhook/releases/tag/v${PREV_WEBHOOK_VERSION} | ||
$generated_by | ||
EOF |