Skip to content

*: try to fix download racing bugs (#2458) #320

*: try to fix download racing bugs (#2458)

*: try to fix download racing bugs (#2458) #320

Workflow file for this run

---
name: release-tiup
on:
push:
branches:
- ci/gh-*
- release-*
- master
paths-ignore:
- '**.html'
- '**.md'
- 'CNAME'
- 'LICENSE'
- 'doc/**'
- 'embed/templates/examples/**'
release:
types:
- published
workflow_dispatch:
inputs:
git-ref:
description: git ref
required: true
jobs:
release:
runs-on: ubuntu-20.04
timeout-minutes: 30
outputs:
REL_VER: ${{ steps.build_tiup.outputs.REL_VER }}
strategy:
fail-fast: true
matrix:
os:
- "linux"
- "darwin"
arch:
- "amd64"
- "arm64"
env:
working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}
steps:
- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: 1.21.x
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
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 's/-[^-]*$//' | sed -r 's/(-[^-]*$)/-nightly\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_tiup
working-directory: ${{ env.working-directory }}
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
COMMIT: ${GITHUB_SHA}
GITREF: ${{ steps.get_git.outputs.GIT_REF }}
actor: ${{ github.actor }}
event: ${{ github.event_name }}
run: |
export GOPATH=${GITHUB_WORKSPACE}/go
export PATH=$PATH:$GOPATH/bin
if [ ! -z ${{ steps.check_staging.outputs.STAGING }} ]; then
export EXTRA_LDFLAGS="-X \"github.com/${{ github.repository }}/pkg/version.TiUPVerName=${{ steps.check_staging.outputs.STAGING }}\""
export REL_VER=${{ steps.check_staging.outputs.STAGING }}
else
export REL_VER=`git describe --tags --always`
fi
echo ::set-output name=REL_VER::$REL_VER
BUILD_FLAGS='-trimpath -mod=readonly -modcacherw -buildvcs=false' make build && \
BUILD_FLAGS='-trimpath -mod=readonly -modcacherw -buildvcs=false' make ctl && \
echo "Build success."
checksum_file=checksum.${{ matrix.os }}-${{ matrix.arch }}.txt
checksum_header="TiUP $REL_VER (${actor}@${event}) ${{ github.run_id }}"
echo ${checksum_header} > ${checksum_file}
echo "sha256sum:" >> ${checksum_file}
sha256sum bin/* >> ${checksum_file}
echo "b2sum:" >> ${checksum_file}
b2sum bin/* >> ${checksum_file}
cat ${checksum_file}
- name: Package components
id: packaging
working-directory: ${{ env.working-directory }}
env:
ARCH: ${{ matrix.os }}-${{ matrix.arch }}
REL_VER: ${{ steps.build_tiup.outputs.REL_VER }}
run: |
TMP_DIR=`mktemp -d`
export TIUP_HOME="$TMP_DIR/home"
echo ::set-output name=TIUP_HOME::$TIUP_HOME
echo ::set-output name=TIUP_BIN::$TIUP_HOME/bin/tiup
rm -rf $TIUP_HOME && mkdir -p $TIUP_HOME/{bin,keys}
wget -O $TMP_DIR/tiup-linux-amd64.tar.gz -q https://tiup-mirrors.pingcap.com/tiup-linux-amd64.tar.gz
tar -zxf $TMP_DIR/tiup-linux-amd64.tar.gz -C $TIUP_HOME/bin && chmod 755 $TIUP_HOME/bin/tiup
curl -s https://tiup-mirrors.pingcap.com/root.json -o $TIUP_HOME/bin/root.json
mkdir -p package
cp $TIUP_HOME/bin/root.json bin/root.json
# make tar reproducible
TAR="tar --sort=name --mtime=${{ steps.get_git.outputs.COMMIT_TIMESTAMP }} --owner=0 --group=0 --numeric-owner"
# package all binaries to upload to github release asset
${TAR} -czf tiup-${REL_VER}-${ARCH}.tar.gz bin checksum.${{ matrix.os }}-${{ matrix.arch }}.txt
# package each component
# tiup-ctl is destributed with other components, so not packaging / publishing here
${TAR} -C bin -czf package/tiup-${REL_VER}-${ARCH}.tar.gz tiup
${TAR} -C bin -czf package/cluster-${REL_VER}-${ARCH}.tar.gz tiup-cluster
${TAR} -C bin -czf package/dm-${REL_VER}-${ARCH}.tar.gz tiup-dm
${TAR} -C bin -czf package/playground-${REL_VER}-${ARCH}.tar.gz tiup-playground
${TAR} -C bin -czf package/client-${REL_VER}-${ARCH}.tar.gz tiup-client
${TAR} -C bin -czf package/server-${REL_VER}-${ARCH}.tar.gz tiup-server
- name: Publish packages
working-directory: ${{ env.working-directory }}
env:
TIUP_MIRRORS: ${{ secrets.TIUP_SERVER_PROD }}
TIUP_HOME: ${{ steps.packaging.outputs.TIUP_HOME }}
TIUP_BIN: ${{ steps.packaging.outputs.TIUP_BIN }}
REL_VER: ${{ steps.build_tiup.outputs.REL_VER }}
ARCH: ${{ matrix.os }}-${{ matrix.arch }}
tiup_desc: "TiUP is a command-line component management tool that can help to download and install TiDB platform components to the local system"
cluster_desc: "Deploy a TiDB cluster for production"
dm_desc: "Data Migration Platform manager"
playground_desc: "Bootstrap a local TiDB cluster for fun"
client_desc: "Client to connect playground"
server_desc: "TiUP publish/cache server"
run: |
${TIUP_BIN} mirror set ${TIUP_MIRRORS}
echo ${{ secrets.TIUP_COMP_KEY_PINGCAP }} | base64 -d > $TIUP_HOME/keys/private.json
# add a random delay before actually publishing, this can help reduce manifest conflict
# when there are multiple jobs running in parallel
sleep $[ ( $RANDOM % 10 ) ]s
${TIUP_BIN} mirror publish tiup ${REL_VER} package/tiup-${REL_VER}-${ARCH}.tar.gz tiup --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${tiup_desc}"
${TIUP_BIN} mirror publish cluster ${REL_VER} package/cluster-${REL_VER}-${ARCH}.tar.gz tiup-cluster --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${cluster_desc}"
${TIUP_BIN} mirror publish dm ${REL_VER} package/dm-${REL_VER}-${ARCH}.tar.gz tiup-dm --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${dm_desc}" --standalone
${TIUP_BIN} mirror publish playground ${REL_VER} package/playground-${REL_VER}-${ARCH}.tar.gz tiup-playground --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${playground_desc}"
${TIUP_BIN} mirror publish client ${REL_VER} package/client-${REL_VER}-${ARCH}.tar.gz tiup-client --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${client_desc}"
${TIUP_BIN} mirror publish server ${REL_VER} package/server-${REL_VER}-${ARCH}.tar.gz tiup-server --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${server_desc}" --hide --standalone
- 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 }}/tiup-${{ steps.build_tiup.outputs.REL_VER }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
artifactContentType: application/gzip
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
prerelease: ${{ github.event.release.prerelease }}
token: ${{ secrets.GITHUB_TOKEN }}
brew-upgrade:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: release
steps:
- name: Check out brew code
uses: actions/checkout@v3
continue-on-error: true
if: github.event_name == 'release'
with:
repository: pingcap/homebrew-brew
persist-credentials: false
ref: master
path: ${{ github.workspace }}/homebrew-brew
fetch-depth: 0
- name: Update and Check tiup version
id: update_version
working-directory: ${{ github.workspace }}/homebrew-brew
continue-on-error: true
if: github.event_name == 'release'
run: |
sed -i 's/version.*/version "${{ needs.release.outputs.REL_VER }}"/g' Formula/tiup.rb
sed -i 's/tag:.*/tag: "${{ needs.release.outputs.REL_VER }}"/g' Formula/tiup.rb
cat Formula/tiup.rb
- name: Push new homebrew
uses: actions-js/push@master
continue-on-error: true
if: github.event_name == 'release'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
directory: ${{ github.workspace }}/homebrew-brew
message: "tiup: ${{ needs.release.outputs.REL_VER }}"
branch: master
repository: pingcap/homebrew-brew