Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: rename release branch #673

Merged
merged 2 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .github/workflows/docker-build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Publish Docker image with a commit hash tag
on:
push:
branches:
- release-**
- release/**

jobs:
push_to_registry:
Expand Down Expand Up @@ -46,20 +46,24 @@ jobs:
# Set up variables for repository and branch name
REPO_OWNER=kubeshop
REPO_NAME=helm-charts
BRANCH_NAME=${GITHUB_REF}
OLD_BRANCH_NAME=${GITHUB_REF}
RELEASE_TAG=$(echo $OLD_BRANCH_NAME | sed 's/[^/]*\///')

# Set up the new branch name
NEW_BRANCH_NAME="release/dashboard/${RELEASE_TAG}"

# Set up authentication using a personal access token
AUTH_HEADER="Authorization: Bearer ${{ secrets.CI_BOT_TOKEN }}"

# Check if branch already exists
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -H "${AUTH_HEADER}" "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/branches/${BRANCH_NAME}")
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -H "${AUTH_HEADER}" "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/branches/${NEW_BRANCH_NAME}")

# If branch doesn't exist, create it
if [ "${STATUS}" -eq 404 ]; then
curl -X POST -H "${AUTH_HEADER}" -d '{"ref": "'"${BRANCH_NAME}"'","sha": "'"$(curl -s -H "${AUTH_HEADER}" "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/git/refs/heads/main" | jq -r '.object.sha')"'"}' "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/git/refs"
echo "Created branch ${BRANCH_NAME} in ${REPO_OWNER}/${REPO_NAME}"
curl -X POST -H "${AUTH_HEADER}" -d '{"ref": "'"${NEW_BRANCH_NAME}"'","sha": "'"$(curl -s -H "${AUTH_HEADER}" "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/git/refs/heads/main" | jq -r '.object.sha')"'"}' "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/git/refs"
echo "Created branch ${NEW_BRANCH_NAME} in ${REPO_OWNER}/${REPO_NAME}"
else
echo "Branch ${BRANCH_NAME} already exists in ${REPO_OWNER}/${REPO_NAME}"
echo "Branch ${NEW_BRANCH_NAME} already exists in ${REPO_OWNER}/${REPO_NAME}"
fi

- name: Repository Dispatch
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/docker-build-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,29 @@ jobs:

export GH_PUSH_TOKEN
export RELEASE_VERSION
export SERVICE

# Check if release branch exists
# Check if release branch exists in helm-charts repository
REPO_OWNER=kubeshop
REPO_NAME=helm-charts
RELEASE_BRANCH_NAME=release-$RELEASE_VERSION
RELEASE_BRANCH_NAME=release/$SERVICE/$RELEASE_VERSION
echo $RELEASE_VERSION
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -H "${AUTH_HEADER}" "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/branches/${RELEASE_BRANCH_NAME}")

if [ "${STATUS}" -eq 404 ]; then
git fetch origin main
git checkout main
cd ./scripts
./chart_releaser.sh --helm-chart-folder testkube-dashboard
./chart_releaser.sh --helm-chart-folder testkube-$SERVICE
else
git fetch origin "release-$RELEASE_VERSION"
git checkout "release-$RELEASE_VERSION"
git fetch origin "release/$SERVICE/$RELEASE_VERSION"
git checkout "release/$SERVICE/$RELEASE_VERSION"
echo "Switched to release branch"
cd ./scripts
./chart_releaser.sh --helm-chart-folder testkube-dashboard --branch true
./chart_releaser.sh --helm-chart-folder testkube-$SERVICE --branch true
fi

env:
SERVICE: dashboard
GH_PUSH_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
RELEASE_VERSION: ${{ steps.tag.outputs.tag }}