Skip to content

.github/workflows/release.yaml #197

.github/workflows/release.yaml

.github/workflows/release.yaml #197

Workflow file for this run

name: Conditional Builds Workflow
on:
release:
types: [created]
push:
branches:
- 'release-*'
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v4
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
name: Build ${{ matrix.app }}-${{ matrix.platform }}-${{ matrix.arch }}
strategy:
fail-fast: false
matrix:
app: [kl,kli]
os: [ubuntu-latest, windows-latest-l, macos-latest, macos-14]
arch: [amd64, arm64]
include:
- os: ubuntu-latest
goos: linux
platform: linux
- os: windows-latest-l
goos: windows
platform: windows
- os: macos-latest
goos: darwin
platform: darwin
- os: macos-14
goos: darwin
platform: darwin
exclude:
- os: macos-14
arch: amd64
- os: macos-latest
arch: arm64
- os: ubuntu-latest
arch: arm64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4.1.1
- name: Setup Go
uses: actions/setup-go@v5.0.0
with:
go-version: '^1.19'
- name: Set up QEMU
if: matrix.arch == 'arm64' && matrix.os == 'ubuntu-latest'
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Setup libappindicator3-dev for linux
if: matrix.goos == 'linux'
run: |
sudo apt-get update
sudo apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev
- name: Check Go version
run: |
go version
echo "[PRE] GOOS: $(go env GOOS) GOARCH: $(go env GOARCH)"
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Create and Set Image Tag
id: tag_name
run: |
import re
import os
ref = os.getenv('GITHUB_REF')
if ref.startswith('refs/heads/release-'):
tag = ref.replace('refs/heads/release-', '')
if not re.search('-nightly$', tag):
tag += "-nightly"
elif ref.startswith('refs/tags/'):
tag = ref.replace('refs/tags/', '')
else:
tag = 'default-tag' # Adjust this fallback tag as necessary
with open(os.getenv('GITHUB_ENV'), 'a') as env_file:
env_file.write(f"TAG={tag}\n")
with open(os.getenv('GITHUB_OUTPUT'), 'a') as env_out:
env_out.write(f"TAG_NAME={tag}\n")
shell: python
- name: Build Linux & Mac
if: matrix.goos == 'linux' || matrix.goos == 'darwin'
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.arch }}
FLAGS: "-X github.com/kloudlite/kl/flags.Version=${{ steps.tag_name.outputs.TAG_NAME }} -X github.com/kloudlite/kl/flags.CliName=${{ matrix.app }}"
RELEASE_NAME: ${{ matrix.app }}-${{ steps.tag_name.outputs.TAG_NAME }}-${{ matrix.platform }}-${{ matrix.arch }}
run: |
echo "[POST] GOOS: $(go env GOOS) GOARCH: $(go env GOARCH)"
echo "Building for ${{ matrix.goos }}, ${{ matrix.arch }}"
mkdir bin
mkdir out
go build -o bin/$RELEASE_NAME -ldflags "${{ env.FLAGS }}" main.go
- name: Build Windows
if: matrix.goos == 'windows'
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.arch }}
FLAGS: "-X github.com/kloudlite/kl/flags.Version=${{ steps.tag_name.outputs.TAG_NAME }} -X github.com/kloudlite/kl/flags.CliName=${{ matrix.app }}"
RELEASE_NAME: ${{ matrix.app }}-${{ steps.tag_name.outputs.TAG_NAME }}-${{ matrix.platform }}-${{ matrix.arch }}
run: |
echo "[POST] GOOS: $(go env GOOS) GOARCH: $(go env GOARCH)"
echo "Building for ${{ matrix.goos }}, ${{ matrix.arch }}"
mkdir bin
mkdir out
go build -o bin/$RELEASE_NAME.exe -ldflags "${{ env.FLAGS }}" main.go
# - name: Decode and Sign on Windows
# if: matrix.goos == 'windows'
# run: |
# echo "${{ secrets.CERT_PFX }}" > certificate.pfx
# $certPassword = ""
# $filePath = "bin/${{ matrix.app }}.exe"
# $signtoolPath = Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits\10\bin\" -Filter signtool.exe -Recurse | Where-Object FullName -like "*x64*" | Select-Object -ExpandProperty FullName -First 1
# if (-not $signtoolPath) {
# throw "Signtool.exe not found"
# }
# & $signtoolPath sign /f certificate.pfx /tr http://timestamp.digicert.com /td sha256 /fd sha256 $filePath
# shell: pwsh
# - name: Zip and Tar Application with OS-specific Naming
# env:
# RELEASE_NAME: ${{ matrix.app }}-${{ steps.tag_name.outputs.TAG_NAME }}-${{ matrix.platform }}-${{ matrix.arch }}
# APP_NAME: ${{ matrix.app }} # Assume this is the base app name without .exe
# run: |
# import os
# import zipfile
# import tarfile
# release_name = os.getenv('RELEASE_NAME')
# app_name = os.getenv('APP_NAME')
# # Append .exe to the app name if the script is running on Windows
# if os.name == 'nt':
# app_name += '.exe'
# out_dir = "out"
# bin_dir = "bin"
# # Ensure the output directory exists
# os.makedirs(out_dir, exist_ok=True)
# # Create ZIP file
# zip_path = os.path.join(out_dir, f"{release_name}.zip")
# with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
# zipf.write(os.path.join(bin_dir, app_name), arcname=app_name)
# # Create TAR.GZ file
# tar_path = os.path.join(out_dir, f"{release_name}.tar.gz")
# with tarfile.open(tar_path, "w:gz") as tarf:
# tarf.add(os.path.join(bin_dir, app_name), arcname=app_name)
# shell: python
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.app }}-${{ matrix.platform }}-${{ matrix.arch }}
path: bin/*
release:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: ${{ github.workspace }}/artifacts
- name: Create and Set Image Tag
id: tag_name
run: |
import re
import os
ref = os.getenv('GITHUB_REF')
if ref.startswith('refs/heads/release-'):
tag = ref.replace('refs/heads/release-', '')
if not re.search('-nightly$', tag):
tag += "-nightly"
elif ref.startswith('refs/tags/'):
tag = ref.replace('refs/tags/', '')
else:
tag = 'default-tag' # Adjust this fallback tag as necessary
with open(os.getenv('GITHUB_ENV'), 'a') as env_file:
env_file.write(f"TAG={tag}\n")
with open(os.getenv('GITHUB_OUTPUT'), 'a') as env_out:
env_out.write(f"TAG_NAME={tag}\n")
shell: python
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: artifacts/**/**
tag_name: ${{ steps.tag_name.outputs.TAG_NAME }}
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}