release-new-version #13
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
# | |
# Triggered when release a new version, tag should be formatted as {dir}-{version} | |
# For example: br-v1.0.1/cdc-v1.0.0/gc-worker-v1.0.0 | |
# | |
name: release-new-version | |
on: | |
release: | |
types: | |
- published | |
workflow_dispatch: | |
inputs: | |
git-ref: | |
description: git ref | |
required: true | |
env: | |
GO_VERSION: 1.21.4 | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
outputs: | |
PROD_VER: ${{ steps.build.outputs.PROD_VER }} | |
PROD_NAME: ${{ steps.build.outputs.PROD_NAME }} | |
PROD_DIR: ${{ steps.build.outputs.PROD_DIR }} | |
strategy: | |
fail-fast: true | |
matrix: | |
os: | |
- "linux" | |
arch: | |
- "amd64" | |
- "arm64" | |
env: | |
working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }} | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: '${{ env.GO_VERSION }}' | |
id: go | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.git-ref || github.event.pull_request.head.sha }} | |
path: go/src/github.com/${{ github.repository }} | |
fetch-depth: 0 | |
- name: Check if this is a staging build | |
id: check_staging | |
working-directory: ${{ env.working-directory }} | |
if: github.event_name != 'release' | |
run: | | |
STAGING_VER=`git describe --tags | sed -r "s/([^-]*-g)/r\1/"` | |
echo ::set-output name=STAGING::$STAGING_VER | |
- name: Get git ref and commit | |
id: get_git | |
working-directory: ${{ env.working-directory }} | |
# when empty, it will be determined by Makefile | |
run: | | |
if [[ $GITHUB_REF == refs/tags/* ]]; then | |
echo ::set-output name=GIT_REF::${GITHUB_REF/refs\/tags\//} | |
elif [[ $GITHUB_REF == refs/heads/* ]]; then | |
echo ::set-output name=GIT_REF::${GITHUB_REF/refs\/heads\//} | |
fi | |
COMMIT_TIMESTAMP=`git show --no-patch --no-notes --pretty='%aI'` | |
echo ::set-output name=COMMIT_TIMESTAMP::$COMMIT_TIMESTAMP | |
- name: Build for ${{ matrix.os }}-${{ matrix.arch }} | |
id: build | |
working-directory: ${{ env.working-directory }} | |
run: | | |
export GOPATH=${GITHUB_WORKSPACE}/go | |
export PATH=$PATH:$GOPATH/bin | |
export GOOS=${{ matrix.os }} | |
export GOARCH=${{ matrix.arch }} | |
if [ ! -z ${{ steps.check_staging.outputs.STAGING }} ]; then | |
export REL_VER=${{ steps.check_staging.outputs.STAGING }}+staging | |
else | |
export REL_VER=`git describe --tags --always` | |
fi | |
if [[ $REL_VER =~ ^(br|cdc|gc-worker)-v.*$ ]];then | |
echo "REL_TAG:"$REL_VER | |
else | |
echo "invalid tag:"$REL_VER | |
exit 1 | |
fi | |
export PROD_DIR=${REL_VER%-v*} # get the directory, br/cdc/gc-worker | |
export PROD_NAME=tikv-${REL_VER%-v*} # concatenate the binary name, tikv-br/tikv-cdc/tikv-gc-worker | |
export PROD_VER=v${REL_VER#*-v} | |
# output the parameters for usage in other steps. | |
echo ::set-output name=PROD_VER::$PROD_VER | |
echo ::set-output name=PROD_NAME::$PROD_NAME | |
echo ::set-output name=PROD_DIR::$PROD_DIR | |
cd $PROD_DIR | |
make release | |
echo "Build success." | |
- name: Package components | |
id: packaging | |
working-directory: ${{ env.working-directory }} | |
env: | |
ARCH: ${{ matrix.os }}-${{ matrix.arch }} | |
PROD_VER: ${{ steps.build.outputs.PROD_VER }} | |
PROD_NAME: ${{ steps.build.outputs.PROD_NAME }} | |
PROD_DIR: ${{ steps.build.outputs.PROD_DIR }} | |
run: | | |
cd $PROD_DIR | |
mkdir package | |
tar -C bin -czvf package/$PROD_NAME-$PROD_VER-$ARCH.tar.gz $PROD_NAME | |
checksum_file=package/$PROD_NAME-$PROD_VER-$ARCH.tar.gz.md5 | |
md5sum package/$PROD_NAME-$PROD_VER-$ARCH.tar.gz >> ${checksum_file} | |
ls package/ | |
- name: Upload the all-in-one tarball to GitHub release | |
uses: ncipollo/release-action@v1 | |
if: github.event_name == 'release' | |
with: | |
allowUpdates: true | |
artifacts: ${{ env.working-directory }}/${{ steps.build.outputs.PROD_DIR }}/package/${{ steps.build.outputs.PROD_NAME }}-${{ steps.build.outputs.PROD_VER }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz* | |
artifactContentType: application/gzip | |
omitBodyDuringUpdate: true | |
omitNameDuringUpdate: true | |
prerelease: ${{ github.event.release.prerelease }} | |
token: ${{ secrets.GITHUB_TOKEN }} |