Release Caddy Middleware #12
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 Caddy Middleware | |
on: | |
push: | |
tags: | |
- 'v*' # Trigger when a tag matching v* is pushed (e.g., v1.0.0) | |
workflow_dispatch: # Allow manual triggering from the GitHub UI | |
permissions: | |
contents: write # Grant write permission for release creation | |
jobs: | |
build-and-release: | |
runs-on: ubuntu-latest # Base build platform for cross-compilation | |
strategy: | |
matrix: | |
goos: [linux, windows, darwin] | |
goarch: [amd64, arm64] | |
exclude: | |
- goos: windows | |
goarch: arm64 # Windows on arm64 is not common, remove it. | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.23.4' # Use your desired go version | |
- name: Extract Tag Name | |
id: extract_tag | |
if: "!startsWith(github.ref, 'refs/heads/')" | |
run: echo "TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT | |
- name: Build Binary | |
env: | |
GOOS: ${{ matrix.goos }} | |
GOARCH: ${{ matrix.goarch }} | |
run: | | |
GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags "-X 'github.com/fabriziosalmi/caddy-waf/middleware.ModuleVersion=${{ steps.extract_tag.outputs.TAG_NAME }}'" -o caddy-waf-${GOOS}-${GOARCH} | |
tar czf caddy-waf-${GOOS}-${GOARCH}.tar.gz caddy-waf-${GOOS}-${GOARCH} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: caddy-waf-${{ matrix.goos }}-${{ matrix.goarch }} | |
path: caddy-waf-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz | |
create-release: | |
runs-on: ubuntu-latest | |
needs: build-and-release # Ensure all builds complete before creating release | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Extract Tag Name | |
id: extract_tag | |
if: "!startsWith(github.ref, 'refs/heads/')" | |
run: echo "TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT | |
- name: Create Release | |
id: create_release | |
if: "!startsWith(github.ref, 'refs/heads/')" | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.extract_tag.outputs.TAG_NAME }} | |
release_name: Release ${{ steps.extract_tag.outputs.TAG_NAME }} | |
body: | | |
This is a release of the Caddy WAF middleware version ${{ steps.extract_tag.outputs.TAG_NAME }}. Please download the appropriate binary for your OS/Architecture. | |
draft: false | |
prerelease: false | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
- name: Upload Release Assets | |
if: "!startsWith(github.ref, 'refs/heads/')" | |
run: | | |
for asset in $(ls *.tar.gz); do | |
echo "Uploading ${asset}" | |
gh release upload ${{ steps.create_release.outputs.upload_url }} ${asset} --clobber | |
done | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |