Skip to content

Merge pull request #253 from grafana/remove-target-address-option #193

Merge pull request #253 from grafana/remove-target-address-option

Merge pull request #253 from grafana/remove-target-address-option #193

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 }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: get go version
run: |
GO_VERSION=$(cat go.mod | grep -e "^go 1\.[0-9]*" | cut -d' ' -f 2)
echo "GO_VERSION=$GO_VERSION" >> $GITHUB_ENV
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- 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: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
elif [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
VERSION=$GITHUB_REF_NAME
else
VERSION=""
fi
COMMIT="$(git rev-parse --short HEAD)"
PKG_VERSION=${VERSION:-dev-$COMMIT}
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "PKG_VERSION=$PKG_VERSION" >> $GITHUB_ENV
- name: build and package disruptor
env:
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
./build-package.sh -v $PKG_VERSION all
- 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@v3
with:
name: binaries
path: dist/
retention-days: 7
- name: Export version
id: export-version
env:
VERSION: ${{ env.VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "pkg_version=$PKG_VERSION" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
build-windows-installer:
runs-on: windows-2019
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@v3
- name: Download binaries
uses: actions/download-artifact@v3
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@v3
with:
name: binaries
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@v3
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
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: binaries
path: dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v2
with:
version: v0.9.1
- name: Log into ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push disruptor image
env:
VERSION: ${{ env.VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
IMAGE_TAG="$REGISTRY/$DISRUPTOR_IMAGE_NAME:${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:
VERSION: ${{ env.VERSION }}
PKG_VERSION: ${{ env.PKG_VERSION }}
run: |
IMAGE_TAG="$REGISTRY/$AGENT_IMAGE_NAME:${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: get release version
run: |
VERSION=$GITHUB_REF_NAME
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v3
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: binaries
path: dist
- name: Generate checksum file
env:
VERSION: ${{ env.VERSION }}
run: sha256sum dist/* > "xk6-disruptor-${VERSION}-checksums.txt"
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ env.VERSION }}
run: |
MESSAGE="$(cat ./releases/${VERSION}.md)"
assets=()
for asset in ./dist/*; do
assets+=("-a" "$asset")
done
hub release create "${assets[@]}" -m "$VERSION" -m "$MESSAGE" "$VERSION"