Build caddy with linkup modules #5
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: Build caddy with linkup modules | |
on: | |
workflow_dispatch: | |
inputs: | |
tag_name: | |
description: 'Tag to use for the release (e.g., v1.0.0)' | |
required: true | |
push: | |
tags: | |
- 'v*' # Trigger workflow on version tags like v1.0.0 | |
jobs: | |
build-and-release: | |
name: Build and Release Caddy with Linkup Modules | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest] | |
arch: [amd64, arm64] | |
steps: | |
# Set up Go environment | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.23' | |
- name: Install xcaddy | |
run: | | |
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest | |
# Build Caddy with custom module | |
- name: Build Caddy with Custom Module | |
run: | | |
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then | |
TARGET_OS="linux" | |
else | |
TARGET_OS="darwin" | |
fi | |
xcaddy build \ | |
--output "caddy-${TARGET_OS}-${{ matrix.arch }}" \ | |
--with github.com/mentimeter/caddy-storage-cf-kv \ | |
--with github.com/caddy-dns/cloudflare | |
env: | |
GOBIN: $HOME/go/bin # Ensure Go binaries are in the PATH | |
# Archive the binary | |
- name: Archive Caddy Binary | |
run: | | |
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then | |
TARGET_OS="linux" | |
else | |
TARGET_OS="darwin" | |
fi | |
tar -czvf caddy-${TARGET_OS}-${{ matrix.arch }}.tar.gz caddy-${TARGET_OS}-${{ matrix.arch }} | |
shell: bash | |
- name: Get Release Info | |
id: get_release | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
let tagName; | |
if (context.eventName === 'workflow_dispatch') { | |
tagName = core.getInput('tag_name'); | |
} else if (context.eventName === 'push' && context.ref.startsWith('refs/tags/')) { | |
tagName = context.ref.replace('refs/tags/', ''); | |
} else { | |
throw new Error('This workflow must be triggered by a push to a tag or a manual dispatch with a tag_name input.'); | |
} | |
const releases = await github.rest.repos.listReleases({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
const release = releases.data.find(r => r.tag_name === tagName); | |
if (!release) { | |
throw new Error(`Release with tag ${tagName} not found.`); | |
} | |
core.setOutput('upload_url', release.upload_url); | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Upload binary to the release | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.get_release.outputs.upload_url }} | |
asset_path: ./caddy-${{ matrix.os == 'ubuntu-latest' && 'linux' || 'darwin' }}-${{ matrix.arch }}.tar.gz | |
asset_name: caddy-${{ matrix.os == 'ubuntu-latest' && 'linux' || 'darwin' }}-${{ matrix.arch }}.tar.gz | |
asset_content_type: application/gzip |