Skip to content

support dumping metrics by instance (#470) #5

support dumping metrics by instance (#470)

support dumping metrics by instance (#470) #5

Workflow file for this run

---
name: release-diag
on:
push:
branches:
- ci/gh-*
- release-*
- master
paths-ignore:
- '**.md'
- 'LICENSE'
- 'docs/**'
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_diag.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_diag
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 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 && \
echo "Build success."
checksum_file=checksum.${{ matrix.os }}-${{ matrix.arch }}.txt
checksum_header="Diag $REL_VER (${actor}@${event}) ${{ github.run_id }}"
echo ${checksum_header} > ${checksum_file}
echo "sha256sum:" >> ${checksum_file}
find ./bin -type f -exec sha256sum {} \;
cat ${checksum_file}
- name: Package components
id: packaging
working-directory: ${{ env.working-directory }}
env:
ARCH: ${{ matrix.os }}-${{ matrix.arch }}
REL_VER: ${{ steps.build_diag.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
#add clinic crt
echo ${{ secrets.CLINIC_CRT }} | base64 -d > ./bin/pingcap.crt
# make tar reproducible
TAR="tar --sort=name --mtime=${{ steps.get_git.outputs.COMMIT_TIMESTAMP }} --owner=0 --group=0 --numeric-owner"
# package each component
cd bin
${TAR} -czf ../diag-${REL_VER}-${ARCH}.tar.gz *
cd ..
- 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_diag.outputs.REL_VER }}
ARCH: ${{ matrix.os }}-${{ matrix.arch }}
diag_desc: "Clinic client for data collection and quick health check"
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 diag ${REL_VER} diag-${REL_VER}-${ARCH}.tar.gz diag --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${diag_desc}"