Skip to content

Release

Release #27

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
env:
GODIRS_NOVENDOR: '`go list ./... | grep -v /vendor/`'
PACKAGE_COMMONS: 'github.com/reportportal/commons-go'
RELEASE_DIR: 'release'
LINUX_ARTIFACT_NAME: 'service-index_linux_amd64'
WINDOWS_ARTIFACT_NAME: 'service-index_win_amd64.exe'
VERSION_PLACEHOLDER: '{{.version}}'
DOCKER_TEMPLATE_FILE: 'DockerfileTmpl'
DOCKER_BUILD_FILE: 'Dockerfile'
BUILD_INFO_LDFLAGS: >-
-ldflags "-extldflags '"-static"'
-X ${PACKAGE_COMMONS}/commons.repo=${GITHUB_REPOSITORY}
-X ${PACKAGE_COMMONS}/commons.branch=${GITHUB_SHA}
-X ${PACKAGE_COMMONS}/commons.buildDate=${BUILD_DATE}
-X ${PACKAGE_COMMONS}/commons.version=${VERSION}"
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
RELEASE_URL: ${{ steps.releaseUrl.outputs.RELEASE_URL }}
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.19.9'
- name: Go Linter
uses: golangci/golangci-lint-action@v3
with:
version: v1.48.0
args: '--deadline 10m'
- name: Go Tests
run: 'go test ${{ env.GODIRS_NOVENDOR }}'
- name: Go Dependencies
run: 'go mod download'
- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2.1.1
with:
name: 'reportportal.io'
email: 'support@reportportal.io'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Tag release
id: tagRelease
run: |
git tag -a v${{ github.event.inputs.version }} -m 'Release ${{ github.event.inputs.version }}'
git push --tags
- name: Create Release
id: createRelease
uses: ncipollo/release-action@v1
with:
tag: v${{ github.event.inputs.version }}
name: Release ${{ github.event.inputs.version }}
- name: Export release URL
id: releaseUrl
run: 'echo "RELEASE_URL=${{ steps.createRelease.outputs.upload_url }}" >> $GITHUB_OUTPUT'
build:
runs-on: ubuntu-latest
needs: 'prepare'
strategy:
matrix:
os: [ 'windows', 'linux' ]
arch: [ 'amd64', 'arm64' ]
exclude:
- os: 'windows'
arch: 'arm64'
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.19.9'
- name: Get Date
run: 'echo "BUILD_DATE=`date +%FT%T%z`" >> $GITHUB_ENV'
- name: Generate name
run: |
if [ "${{ matrix.os }}" = "windows" ]; then
ARTIFACT_NAME_POSTFIX=".exe"
fi
echo "ARTIFACT_NAME=service-index_${{ matrix.os }}_${{ matrix.arch }}${ARTIFACT_NAME_POSTFIX}" >> $GITHUB_ENV
- name: Go Build
env:
CGO_ENABLED: 0
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
VERSION: ${{ github.event.inputs.version }}
run: |
if [ "${{ matrix.os }}" = "windows" ]; then
export CGO_ENABLED=0
fi
go build ${{ env.BUILD_INFO_LDFLAGS }} -o ${{ env.RELEASE_DIR }}/${{ env.ARTIFACT_NAME }} ./
file ${{ env.RELEASE_DIR }}/${{ env.ARTIFACT_NAME }}
- name: Upload Binary Asset
id: upload-binary-asset
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
RELEASE_URL=`echo '${{ needs.prepare.outputs.RELEASE_URL }}' | sed -E 's/\{[^}]*\}//'`
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"${RELEASE_URL}?name=${{ env.ARTIFACT_NAME }}" \
--data-binary "@${{ env.RELEASE_DIR }}/${{ env.ARTIFACT_NAME }}"
finish:
runs-on: ubuntu-latest
needs: 'build'
steps:
- uses: actions/checkout@v3
- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2.1.1
with:
name: 'reportportal.io'
email: 'support@reportportal.io'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update Dockerfile
id: dockerfileUpdate
run: |
sed 's/${{ env.VERSION_PLACEHOLDER }}/${{ github.event.inputs.version }}/g' ${{ env.DOCKER_TEMPLATE_FILE }} > ${{ env.DOCKER_BUILD_FILE }}
git add ${{ env.DOCKER_BUILD_FILE }}
export CHANGED=`git status | grep ${{ env.DOCKER_BUILD_FILE }} | xargs`
[ -z "${CHANGED}" ] || git commit -m "Dockerfile update"
- name: Bump version
uses: HardNorth/github-version-generate@v1
with:
version: ${{ github.event.inputs.version }}-SNAPSHOT
next-version-increment-patch: true
- name: Commit version
run: |
echo ${{ env.NEXT_VERSION }} > ${{ github.workspace }}/VERSION
git add ${{ github.workspace }}/VERSION
export CHANGED=`git status | grep VERSION | xargs`
[ -z "${CHANGED}" ] || git commit -m 'Bump new snapshot version'
git push