Merge pull request #77 from cybozu-go/add-proxy-support #3
Workflow file for this run
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
name: "Release" | |
on: | |
push: | |
tags: | |
- "v*" | |
jobs: | |
release: | |
name: "release" | |
runs-on: "ubuntu-22.04" | |
steps: | |
- name: "Validate Release Version" | |
id: check_version | |
run: | | |
VERSION=$(echo $GITHUB_REF | sed -ne 's/[^0-9]*\([0-9]\+\.[0-9]\+\.[0-9]\+\(-.*\)\?\).*/\1/p') | |
if [ "$VERSION" = "" ]; then | |
echo "Invalid version format. $GITHUB_REF" | |
exit 1 | |
fi | |
if [ $(echo $VERSION | grep "-") ]; then PRERELEASE=true; else PRERELEASE=false; fi | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
echo "prerelease=${PRERELEASE}" >> $GITHUB_OUTPUT | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: "go.mod" | |
- run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- run: make docker-build IMG=ghcr.io/cybozu-go/mantle:${{ steps.check_version.outputs.version }} | |
- run: docker push ghcr.io/cybozu-go/mantle:${{ steps.check_version.outputs.version }} | |
- name: "Push branch tag" | |
if: ${{ steps.check_version.outputs.prerelease == 'false' }} | |
run: | | |
BRANCH=$(echo ${{ steps.check_version.outputs.version }} | cut -d "." -f 1-2) | |
docker tag ghcr.io/cybozu-go/mantle:${{ steps.check_version.outputs.version }} ghcr.io/cybozu-go/mantle:${BRANCH} | |
docker push ghcr.io/cybozu-go/mantle:${BRANCH} | |
- name: "Get previous tag" | |
id: get_previous_tag | |
run: | | |
# see https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#list-matching-references | |
RESP=$(gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/${{ github.repository }}/git/matching-refs/tags/v) | |
PREV_TAG=$(echo ${RESP} | jq -r '.[].ref' | awk -F "/" '{print $3}' | \ | |
grep -E "^v[0-9]+\.[0-9]+\.[0-9]+" | sort -V -r | tail -n +2 | head -n 1) | |
if [ -z "${PREV_TAG}" ]; then | |
echo "PREV_TAG is empty." | |
exit 1 | |
fi | |
echo "previous_tag=${PREV_TAG}" >> ${GITHUB_OUTPUT} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Create Release" | |
id: create_release | |
run: | | |
gh release create -t "Release ${GITHUB_REF_NAME}" -d --prerelease=${{ steps.check_version.outputs.prerelease }} \ | |
--generate-notes --notes-start-tag "${{ steps.get_previous_tag.outputs.previous_tag }}" "${GITHUB_REF_NAME}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |