chore: update build workflow #9
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
tags: | |
- '*' | |
permissions: | |
contents: write | |
packages: write | |
env: | |
CHART_NAME: cardano-validator-watcher | |
CHART_DIRECTORY: charts | |
REGISTRY: oci://ghcr.io/kilnfi/charts | |
jobs: | |
build: | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest] | |
arch: [amd64, arm64] | |
runs-on: ${{ matrix.os }} | |
env: | |
CGO_ENABLED: 1 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Export Variables | |
id: export-variables | |
run: | | |
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then | |
echo "os_name=linux" >> $GITHUB_OUTPUT | |
elif [ "${{ matrix.os }}" = "macos-latest" ]; then | |
echo "os_name=darwin" >> $GITHUB_OUTPUT | |
elif [ "${{ matrix.os }}" = "windows-latest" ]; then | |
echo "os_name=windows" >> $GITHUB_OUTPUT | |
fi | |
- name: Install dependencies on Linux | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y build-essential | |
- name: Install dependencies on macOS | |
if: runner.os == 'macOS' | |
run: | | |
brew update | |
brew install sqlite | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.23 | |
- name: Build binary | |
run: | | |
mkdir -p dist | |
ARCH_NAME=${{ matrix.arch }} | |
OUTPUT_FILE="cardano-validator-watcher_${{ github.ref_name }}_${{ steps.export-variables.outputs.os_name }}_${ARCH_NAME}" | |
if [ "$OS_NAME" = "linux" ] && [ "$ARCH_NAME" = "arm" ]; then | |
echo "Building for Linux ARM with specific toolchain" | |
CC=arm-linux-gnueabihf-gcc \ | |
CXX=arm-linux-gnueabihf-g++ \ | |
CGO_ENABLED=1 \ | |
GOOS=linux \ | |
GOARCH=arm \ | |
GOARM=7 \ | |
go build -v -o dist/${OUTPUT_FILE} cmd/watcher/main.go | |
else | |
echo "Building for $OS_NAME $ARCH_NAME" | |
CGO_ENABLED=1 \ | |
GOOS=$OS_NAME \ | |
GOARCH=$ARCH_NAME \ | |
go build -ldflags="-s -w" -o dist/${OUTPUT_FILE} cmd/watcher/main.go | |
fi | |
- name: List dist directory | |
run: ls -la dist/ | |
- name: Upload binaries to release | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: dist/*.tar.gz | |
tag: ${{ github.ref_name }} | |
file_glob: true | |
binaries: | |
if: false | |
runs-on: ubuntu-latest | |
container: | |
image: docker.io/goreleaser/goreleaser-cross:v1.23 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.23 | |
- name: Run GoReleaser | |
uses: goreleaser/goreleaser-action@v6 | |
with: | |
distribution: goreleaser | |
version: '~> v2' | |
args: release --clean | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
images: | |
if: false | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: docker/build-push-action@v6 | |
name: Build & Push Container Images | |
with: | |
context: . | |
file: Dockerfile | |
labels: |- | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.name=cardano-validator-watcher" | |
org.opencontainers.image.version=${{ github.ref_name }}" | |
org.opencontainers.image.authors=contact@kiln.fi" | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: |- | |
ghcr.io/${{ github.repository_owner }}/cardano-validator-watcher:${{ github.ref_name }} | |
ghcr.io/${{ github.repository_owner }}/cardano-validator-watcher:latest | |
helm-chart: | |
if: false | |
needs: images | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Helm | |
uses: azure/setup-helm@v4.2.0 | |
with: | |
version: v3.16.4 | |
- name: Verify Chart Version | |
run: | | |
TAG=$(echo ${{ github.ref_name }} | sed 's/v//') | |
CHART_VERSION=$(yq -r .version ${{ env.CHART_DIRECTORY }}/${{ env.CHART_NAME }}/Chart.yaml) | |
if [ "$TAG" != "${CHART_VERSION}" ]; then | |
echo "Version mismatch: release tag ${TAG} does not match Chart.yaml version ${CHART_VERSION}" | |
exit 1 | |
fi | |
echo "CHART_VERSION=$CHART_VERSION" >> $GITHUB_ENV | |
- name: Helm Registry Login | |
run: | | |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io --username ${{ env.USERNAME }} --password-stdin | |
env: | |
USERNAME: kilnfi | |
- name: 'Helm Package' | |
id: helm-package | |
run: | | |
helm package ${{ env.CHART_DIRECTORY }}/${{ env.CHART_NAME }} --version $CHART_VERSION | |
- name: 'Helm Push' | |
run: | | |
helm push ./cardano-validator-watcher-$CHART_VERSION.tgz ${{ env.REGISTRY }} |