-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BI-5119: ci: add release workflows (#176)
* BI-5119: ci: add release workflows * fix: typo
- Loading branch information
Showing
7 changed files
with
348 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,45 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
version=$1 | ||
version_shift=$2 | ||
|
||
if [[ -z $version ]]; then | ||
echo "ERROR: No version provided, exiting..." | ||
exit 1; | ||
fi | ||
|
||
if [[ -z $version_shift ]]; then | ||
echo "ERROR: No version shift provided, exiting..." | ||
exit 1; | ||
fi | ||
|
||
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
echo "ERROR: Version must be in format X.Y.Z, found $version, exiting..." | ||
exit 1; | ||
fi | ||
|
||
major=$(echo "$version" | cut -d. -f1) | ||
minor=$(echo "$version" | cut -d. -f2) | ||
patch=$(echo "$version" | cut -d. -f3) | ||
|
||
case "$version_shift" in | ||
"major") | ||
major=$((major + 1)) | ||
minor=0 | ||
patch=0 | ||
;; | ||
"minor") | ||
minor=$((minor + 1)) | ||
patch=0 | ||
;; | ||
"patch") | ||
patch=$((patch + 1)) | ||
;; | ||
*) | ||
echo "ERROR: Version shift must be one of [major, minor, patch], found $version_shift, exiting..." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
echo "${major}.${minor}.${patch}" |
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 @@ | ||
name: "🚀🟢 Release" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
type: string | ||
description: "Version to release" | ||
make_latest: | ||
type: boolean | ||
description: "Make latest" | ||
default: true | ||
draft: | ||
type: boolean | ||
description: "Is draft" | ||
default: false | ||
|
||
jobs: | ||
release: | ||
name: "Create release" | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
env: | ||
branch: "release/${{ github.event.inputs.version }}" | ||
steps: | ||
|
||
- name: Checkout code | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: "${{ env.branch }}" | ||
fetch-depth: 0 | ||
|
||
- name: Create release | ||
id: create_release | ||
working-directory: .github/.scripts | ||
run: | | ||
gh release create \ | ||
--repo ${{ github.repository_owner }}/${{ github.event.repository.name }} \ | ||
${{ github.event.inputs.version }} \ | ||
--target ${{ env.branch }} \ | ||
${{ github.event.inputs.make_latest == 'true' && '--latest' || '' }} \ | ||
${{ github.event.inputs.draft == 'true' && '--draft' || '' }} \ | ||
--generate-notes | ||
env: | ||
GH_TOKEN: ${{ github.token }} |
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,80 @@ | ||
name: "🩹 Create Release Hotfix Branch" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
type: string | ||
description: "Version to use as hotfix base, patch version will be increased" | ||
cherry_pick_commits: | ||
type: string | ||
description: "Commits to cherry pick, separated by space" | ||
|
||
jobs: | ||
create_release_hotfix_branch: | ||
name: "Create Release Hotfix" | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
env: | ||
branch: "release/${{ github.event.inputs.version }}" | ||
steps: | ||
|
||
- name: Checkout code | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: "${{ env.branch }}" | ||
fetch-depth: 0 | ||
|
||
- name: Create hotfix branch | ||
id: create_branch | ||
working-directory: .github/.scripts | ||
run: | | ||
version=${{ github.event.inputs.version }} | ||
hotfix_version=$(./shift_version.sh ${version} patch) | ||
hotfix_branch="release/${hotfix_version}" | ||
git checkout -b ${hotfix_branch} "${{ env.branch }}" | ||
git push origin ${hotfix_branch} | ||
echo "hotfix_version=${hotfix_version}" >> $GITHUB_OUTPUT | ||
echo "hotfix_branch=${hotfix_branch}" >> $GITHUB_OUTPUT | ||
- name: Create hotfix PR Branch | ||
id: create_pr_branch | ||
run: | | ||
hotfix_pr_branch="hotfix/${{ steps.create_branch.outputs.hotfix_version }}" | ||
git checkout -b ${hotfix_pr_branch} ${{ steps.create_branch.outputs.hotfix_branch }} | ||
git push origin ${hotfix_pr_branch} | ||
echo "hotfix_pr_branch=${hotfix_pr_branch}" >> $GITHUB_OUTPUT | ||
- name: Setup git user | ||
id: setup_git_user | ||
if: ${{ github.event.inputs.cherry_pick_commits != '' }} | ||
run: | | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --global user.name "github-actions[bot]" | ||
- name: Cherry pick commits | ||
id: cherry_pick | ||
if: ${{ github.event.inputs.cherry_pick_commits != '' }} | ||
run: | | ||
git cherry-pick ${{ github.event.inputs.cherry_pick_commits }} | ||
git push origin ${{ steps.create_pr_branch.outputs.hotfix_pr_branch }} | ||
- name: Create pull request | ||
id: create_pull_request | ||
if: ${{ github.event.inputs.cherry_pick_commits != '' }} | ||
run: | | ||
gh pr create \ | ||
--repo ${{ github.repository_owner }}/${{ github.event.repository.name }} \ | ||
--base ${{ steps.create_branch.outputs.hotfix_branch }} \ | ||
--head ${{ steps.create_pr_branch.outputs.hotfix_pr_branch }} \ | ||
--title "Hotfix ${{ steps.create_branch.outputs.hotfix_version }}" \ | ||
--body "Hotfix ${{ steps.create_branch.outputs.hotfix_version }}" | ||
env: | ||
GH_TOKEN: ${{ github.token }} |
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,87 @@ | ||
name: "🚀🟡 Prerelease" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
type: string | ||
description: "Version to release" | ||
version_shift: | ||
type: choice | ||
description: "Version shift, used if version is not specified" | ||
options: | ||
- "major" | ||
- "minor" | ||
- "patch" | ||
default: "minor" | ||
branch: | ||
type: string | ||
description: "Target branch to release" | ||
default: "main" | ||
with_release: | ||
type: boolean | ||
description: "Create green release as well" | ||
default: false | ||
|
||
jobs: | ||
release: | ||
name: "Create prerelease" | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout code | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: "${{ github.event.inputs.branch }}" | ||
fetch-depth: 0 | ||
|
||
- name: Get version | ||
id: get_version | ||
working-directory: .github/.scripts | ||
run: | | ||
version=${{ github.event.inputs.version }} | ||
if [[ -z "${version}" ]]; then | ||
latest_tag=$(git describe --tags --abbrev=0) | ||
latest_version="${latest_tag%rc*}" | ||
echo "Latest version is ${latest_version}" | ||
version=$(./shift_version.sh ${latest_version} ${{ github.event.inputs.version_shift }}) | ||
fi | ||
release_branch="release/${version}" | ||
tag_name="${version}rc1" | ||
echo "version=${version}" >> $GITHUB_OUTPUT | ||
echo "release_branch=${release_branch}" >> $GITHUB_OUTPUT | ||
echo "tag_name=${tag_name}" >> $GITHUB_OUTPUT | ||
- name: Create and push release branch | ||
id: create_branch | ||
if: ${{ github.event.inputs.branch != steps.get_version.outputs.release_branch }} | ||
run: | | ||
git branch ${{ steps.get_version.outputs.release_branch }} | ||
git push origin ${{ steps.get_version.outputs.release_branch }} | ||
- name: Create prerelease | ||
id: create_prerelease | ||
run: | | ||
gh release create \ | ||
--repo ${{ github.repository_owner }}/${{ github.event.repository.name }} \ | ||
${{ steps.get_version.outputs.tag_name }} \ | ||
--target ${{ steps.get_version.outputs.release_branch }} \ | ||
--prerelease \ | ||
--generate-notes | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
|
||
- name: Create release | ||
id: create_release | ||
if: ${{ github.event.inputs.with_release == 'true' }} | ||
run: | | ||
gh release create \ | ||
--repo ${{ github.repository_owner }}/${{ github.event.repository.name }} \ | ||
${{ steps.get_version.outputs.version }} \ | ||
--target ${{ steps.get_version.outputs.release_branch }} \ | ||
--generate-notes | ||
env: | ||
GH_TOKEN: ${{ github.token }} |
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,42 @@ | ||
name: "🔒 Protect Release Branches" | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- release/* | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
|
||
jobs: | ||
protect-release-branches: | ||
name: "Protect Release Branches" | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
steps: | ||
- name: Checkout code | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
fetch-depth: 0 | ||
|
||
- name: Check if tag already exists | ||
id: check_tag | ||
run: | | ||
branch_name=${{ github.event.pull_request.base.ref }} | ||
version=${branch_name#"release/"} | ||
git fetch --tags | ||
echo "Checking if tag ${version} already exists..." | ||
if [[ -n $(git tag -l "${version}") ]]; then | ||
echo "Release tag ${version} already exists, thus this branch cannot be changed." | ||
exit 1; | ||
fi | ||
if [[ -n $(git tag -l "${version}rc*") ]]; then | ||
echo "Release candidate tag ${version}rc* already exists, thus this branch cannot be changed." | ||
exit 1; | ||
fi |
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
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,43 @@ | ||
version: 3 | ||
|
||
vars: | ||
repo: datalens-tech/datalens-backend | ||
|
||
tasks: | ||
prerelease: | ||
cmds: | ||
- gh workflow run "release_prerelease.yaml" | ||
--repo {{.repo}} | ||
--ref main | ||
{{ if .version }}--field version="{{.version}}"{{ end }} | ||
{{ if .version_shift }}--field version_shift="{{.version_shift}}"{{ end }} | ||
--field branch="{{.branch}}" | ||
--field with_release="{{.with_release}}" | ||
vars: | ||
version_shift: '{{default "minor" .version_shift}}' | ||
branch: '{{default "main" .branch}}' | ||
with_release: '{{default "false" .with_release}}' | ||
|
||
release: | ||
requires: | ||
vars: [version] | ||
cmds: | ||
- gh workflow run "release.yaml" | ||
--repo {{.repo}} | ||
--ref main | ||
-f version={{.version}} | ||
-f make_latest={{.make_latest}} | ||
-f draft={{.draft}} | ||
vars: | ||
make_latest: '{{default "false" .make_latest}}' | ||
draft: '{{default "false" .draft}}' | ||
|
||
create_hotfix: | ||
requires: | ||
vars: [version, commits] | ||
cmds: | ||
- gh workflow run "release_create_hotfix_branch.yaml" | ||
--repo {{.repo}} | ||
--ref main | ||
-f version={{.version}} | ||
-f cherry_pick_commits="{{.commits}}" |