Skip to content

Commit

Permalink
Add release workflows
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Dec 13, 2023
1 parent 2664295 commit 8c4ceed
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/.kodiak.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version = 1

[merge]
method = "squash" # default: "merge"
delete_branch_on_merge = true # default: false
optimistic_updates = true # default: true
prioritize_ready_to_merge = true # default: false

[merge.message]
title = "pull_request_title" # default: "github_default"
body = "github_default" # default: "github_default"
strip_html_comments = true # default: false

[update]
always = true # default: false

[approve]
auto_approve_usernames = ["1gtm", "tamalsaha"]
54 changes: 54 additions & 0 deletions .github/workflows/release-tracker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: release-tracker

on:
pull_request:
types: [closed]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
label-detector:
name: Runner Label
runs-on: label-detector
outputs:
runs-on: ${{ steps.detector.outputs.label }}
steps:
- name: Detect Label
id: detector
run: |
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idoutputs
echo "label=$(curl -fsSL https://this-is-nats.appscode.ninja/runs-on/${{ github.repository_owner }}?visibility=${{ github.repository_visibility }})" >> $GITHUB_OUTPUT
build:
name: Build
needs: label-detector
runs-on: "${{ needs.label-detector.outputs.runs-on }}"
steps:
- uses: actions/checkout@v1

- name: Prepare git
env:
GITHUB_USER: 1gtm
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
run: |
git config --global user.name "${GITHUB_USER}"
git config --global user.email "${GITHUB_USER}@appscode.com"
git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
- name: Install GitHub CLI
run: |
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
sudo mv bin/hub /usr/local/bin
- name: Update release tracker
if: |
github.event.action == 'closed' &&
github.event.pull_request.merged == true
env:
GITHUB_USER: 1gtm
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
run: |
./hack/scripts/update-release-tracker.sh
70 changes: 70 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Release

on:
push:
tags:
- "*.*"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
label-detector:
name: Runner Label
runs-on: label-detector
outputs:
runs-on: ${{ steps.detector.outputs.label }}
steps:
- name: Detect Label
id: detector
run: |
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idoutputs
echo "label=$(curl -fsSL https://this-is-nats.appscode.ninja/runs-on/${{ github.repository_owner }}?visibility=${{ github.repository_visibility }})" >> $GITHUB_OUTPUT
build:
name: Build
needs: label-detector
runs-on: "${{ needs.label-detector.outputs.runs-on }}"
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Set up Go 1.21
uses: actions/setup-go@v1
with:
go-version: '1.21'
id: go

- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Prepare Host
run: |
sudo apt-get -qq update || true
sudo apt-get install -y unzip
go install golang.org/x/tools/cmd/goimports@latest
- name: Publish to GitHub Container Registry
env:
REGISTRY: ghcr.io/kubedb
DOCKER_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
USERNAME: 1gtm
APPSCODE_ENV: prod
run: |
docker login ghcr.io --username ${USERNAME} --password ${DOCKER_TOKEN}
make submodules
make generate
make build.all
make publish
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.event.ref, 'refs/tags/') && (contains(github.ref, '-alpha.') || contains(github.ref, '-beta.')) == false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72 changes: 72 additions & 0 deletions hack/scripts/update-release-tracker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

# Copyright AppsCode Inc. and Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eou pipefail

# ref: https://gist.github.com/joshisa/297b0bc1ec0dcdda0d1625029711fa24
parse_url() {
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
# remove the protocol
url="$(echo ${1/$proto/})"

IFS='/' # / is set as delimiter
read -ra PARTS <<<"$url" # str is read into an array as tokens separated by IFS
if [ ${PARTS[0]} != 'github.com' ] || [ ${#PARTS[@]} -ne 5 ]; then
echo "failed to parse relase-tracker: $url"
exit 1
fi
export RELEASE_TRACKER_OWNER=${PARTS[1]}
export RELEASE_TRACKER_REPO=${PARTS[2]}
export RELEASE_TRACKER_PR=${PARTS[4]}
}

RELEASE_TRACKER=${RELEASE_TRACKER:-}
GITHUB_BASE_REF=${GITHUB_BASE_REF:-}

while IFS=$': \r\t' read -r -u9 marker v; do
case $marker in
Release-tracker)
export RELEASE_TRACKER=$(echo $v | tr -d '\r\t')
;;
Release)
export RELEASE=$(echo $v | tr -d '\r\t')
;;
esac
done 9< <(git show -s --format=%b)

[ ! -z "$RELEASE_TRACKER" ] || {
echo "Release-tracker url not found."
exit 0
}

[ ! -z "$GITHUB_BASE_REF" ] || {
echo "GitHub base ref not found."
exit 0
}

parse_url $RELEASE_TRACKER
api_url="repos/${RELEASE_TRACKER_OWNER}/${RELEASE_TRACKER_REPO}/issues/${RELEASE_TRACKER_PR}/comments"

case $GITHUB_BASE_REF in
master)
msg="/ready-to-tag github.com/${GITHUB_REPOSITORY} ${GITHUB_SHA}"
;;
*)
msg="/cherry-picked github.com/${GITHUB_REPOSITORY} ${GITHUB_BASE_REF} ${GITHUB_SHA}"
;;
esac

hub api "$api_url" -f body="$msg"

0 comments on commit 8c4ceed

Please sign in to comment.