Skip to content

Commit

Permalink
add mantle release workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Shinya Hayashi <[email protected]>
  • Loading branch information
peng225 committed Jun 25, 2024
1 parent 4e41ae9 commit 4197da4
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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 }}

0 comments on commit 4197da4

Please sign in to comment.