Skip to content

ci/cd: tiny changes to the release script #25

ci/cd: tiny changes to the release script

ci/cd: tiny changes to the release script #25

Workflow file for this run

name: Release CLI
on:
push:
tags:
- "cli/v*"
permissions:
contents: write
jobs:
release:
runs-on: proxmox-lxc
defaults:
run:
working-directory: cli
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Set version
id: version
run: |
VERSION=${GITHUB_REF_NAME#cli/}
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Build binaries
run: |
mkdir -p dist
platforms=("darwin/amd64" "darwin/arm64" "windows/amd64" "windows/arm64" "linux/amd64" "linux/arm64")
for platform in "${platforms[@]}"; do
GOOS="${platform%/*}"
GOARCH="${platform#*/}"
output="dist/odsci-$VERSION-$GOOS-$GOARCH"
[ "$GOOS" = "windows" ] && output="$output.exe"
GOOS=$GOOS GOARCH=$GOARCH go build \
-ldflags="-s -w -X github.com/sthivaios/odsci/cmd.Version=$VERSION" \
-o "$output" .
done
- name: Create archives
run: |
cd dist
for f in odsci-*-darwin-* odsci-*-linux-*; do
tar -czf "${f}.tar.gz" "$f" && rm "$f"
done
for f in odsci-*.exe; do
zip "${f%.exe}.zip" "$f" && rm "$f"
done
- name: Generate checksums
run: |
cd dist
sha256sum * > checksums.txt
- name: Extract changelog
id: changelog
run: |
VERSION=${GITHUB_REF_NAME#cli/}
CHANGES=$(awk -v ver="$VERSION" '
$0 ~ "^## \\[" ver "\\]" {found=1; next}
$0 ~ "^## \\[" {found=0}
found {print}
' CHANGELOG.md)
if [ -z "$CHANGES" ]; then
CHANGES="No changelog entry was found for this release."
fi
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v1
with:
body: ${{ steps.changelog.outputs.changelog }}
files: cli/dist/*