Skip to content

simplify release workflow (#436) #336

simplify release workflow (#436)

simplify release workflow (#436) #336

Workflow file for this run

name: publish
on:
workflow_dispatch:
inputs:
version:
description: 'The version of the release in semver format. If it is a development release append a build metadata (e.g. v0.38.0-dev).'
required: true
push:
branches:
- main
tags:
- v*
env:
REGISTRY: ghcr.io
DISRUPTOR_IMAGE_NAME: grafana/xk6-disruptor
AGENT_IMAGE_NAME: grafana/xk6-disruptor-agent
jobs:
build-binaries:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
version: ${{ steps.export-version.outputs.version}}
pkg_version: ${{ steps.export-version.outputs.pkg_version }}
image_version: ${{ steps.export-version.outputs.image_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install xk6 (k6 extension builder)
run: |
go install go.k6.io/xk6/cmd/xk6@latest
- name: Install nfpm (dep and rpm package builder)
run: |
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]
- name: get-version
run: |
COMMIT="$(git rev-parse --short HEAD)"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
IMAGE_VERSION=$VERSION
elif [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
VERSION=$GITHUB_REF_NAME
IMAGE_VERSION=$VERSION
else
VERSION=""
IMAGE_VERSION="latest"
fi
PKG_VERSION=${VERSION:-dev-$COMMIT}
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "PKG_VERSION=$PKG_VERSION" >> $GITHUB_ENV
echo "IMAGE_VERSION=$IMAGE_VERSION" >> $GITHUB_ENV
- name: build and package disruptor
env:
VERSION: ${{ env.VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
if [[ -n $VERSION ]]; then
VERSION="-v $VERSION"
fi
./release.sh $VERSION -r $PKG_VERSION
- name: Build and package agent
env:
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
for ARCH in "amd64" "arm64"; do
AGENT="xk6-disruptor-agent"
GOARCH=$ARCH CGO_ENABLED=0 go build -o build/$AGENT-linux-$ARCH ./cmd/agent
tar -zcf dist/$AGENT-${PKG_VERSION}-linux-$ARCH.tar.gz -C build/ $AGENT-linux-$ARCH
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binaries
path: dist/
retention-days: 7
- name: Export version
id: export-version
env:
VERSION: ${{ env.VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
IMAGE_VERSION: ${{ env.IMAGE_VERSION }}
run: |
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "pkg_version=$PKG_VERSION" >> $GITHUB_OUTPUT
echo "image_version=$IMAGE_VERSION" >> $GITHUB_OUTPUT
build-windows-installer:
runs-on: windows-2022
needs: [build-binaries]
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
defaults:
run:
shell: pwsh
steps:
- name: get package info
run: |
# remove 'v' from version as windows only manage numeric version numbers
$Env:VERSION=$Env:GITHUB_REF_NAME.trim("v")
echo "VERSION=$Env:VERSION" >> $Env:GITHUB_ENV
echo "PKGNAME=xk6-disruptor-v$Env:VERSION-windows-amd64" >> $Env:GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v4
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries
path: dist
- name: Install wix tools
run: |
curl -Lso wix311-binaries.zip https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip
Expand-Archive -Path .\wix311-binaries.zip -DestinationPath .\packaging\wix311\
- name: Unzip Windows binary
run: |
Expand-Archive -Path ".\dist\$Env:PKGNAME.zip" -DestinationPath .\packaging\
- name: Build msi
run: |
cd .\packaging
.\wix311\candle.exe -arch x64 "-dVERSION=$Env:VERSION" xk6disruptor.wxs
.\wix311\light.exe -ext WixUIExtension -o "$Env:PKGNAME.msi" xk6disruptor.wixobj
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: windows-installer
path: |
packaging/*.msi
retention-days: 7
publish-images:
runs-on: ubuntu-latest
needs: [build-binaries]
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get image version
run: |
echo "VERSION=${{needs.build-binaries.outputs.version}}" >> $GITHUB_ENV
echo "PKG_VERSION=${{needs.build-binaries.outputs.pkg_version}}" >> $GITHUB_ENV
echo "IMAGE_VERSION=${{needs.build-binaries.outputs.image_version}}" >> $GITHUB_ENV
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries
path: dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.9.1
- name: Log into ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push disruptor image
env:
IMAGE_VERSION: ${{ env.IMAGE_VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
IMAGE_TAG="$REGISTRY/$DISRUPTOR_IMAGE_NAME:${IMAGE_VERSION:-latest}"
mkdir images/disruptor/build/
cat dist/xk6-disruptor-${PKG_VERSION}-linux-*.tar.gz | tar -xzf - -i -C images/disruptor/build/
docker buildx build -t $IMAGE_TAG --platform=linux/amd64,linux/arm64 images/disruptor --push
- name: Build and push agent image
env:
IMAGE_VERSION: ${{ env.IMAGE_VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
IMAGE_TAG="$REGISTRY/$AGENT_IMAGE_NAME:${IMAGE_VERSION:-latest}"
mkdir images/agent/build/
cat dist/xk6-disruptor-agent-${PKG_VERSION}-linux-*.tar.gz | tar -xzf - -i -C images/agent/build/
docker buildx build -t $IMAGE_TAG --platform=linux/amd64,linux/arm64 images/agent --push
release-packages:
runs-on: ubuntu-latest
needs: [build-binaries, build-windows-installer]
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries
path: dist
- name: Download Windows installer
uses: actions/download-artifact@v4
with:
name: windows-installer
path: dist
- name: Generate checksum file
run: sha256sum dist/* > "xk6-disruptor-${{ github.REF_NAME }}-checksums.txt"
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "${{ github.REF_NAME }}" ./dist/*