Skip to content

trigger new version

trigger new version #5

Workflow file for this run

name: Release
on:
push:
branches:
- main
permissions:
contents: write
packages: write
jobs:
release:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Get next version
id: version
run: |
# Get the latest tag, if no tags exist, start with v0.0.0
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
# Extract version numbers
VERSION=${LATEST_TAG#v}
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION"
MAJOR=${VERSION_PARTS[0]:-0}
MINOR=${VERSION_PARTS[1]:-0}
PATCH=${VERSION_PARTS[2]:-0}
# Increment patch version
PATCH=$((PATCH + 1))
# If this is the first release and we're starting from v0.0.0, set to v0.0.1
if [ "$LATEST_TAG" = "v0.0.0" ]; then
NEW_VERSION="v0.0.1"
else
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
fi
echo "New version: $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag ${{ steps.version.outputs.version }}
git push origin ${{ steps.version.outputs.version }}
build:
needs: release
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
suffix: ""
- goos: linux
goarch: arm64
suffix: ""
- goos: darwin
goarch: amd64
suffix: ""
- goos: darwin
goarch: arm64
suffix: ""
- goos: windows
goarch: amd64
suffix: ".exe"
- goos: windows
goarch: arm64
suffix: ".exe"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
BINARY_NAME="github-copilot-svcs-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.suffix }}"
go build -ldflags="-s -w -X main.version=${{ needs.release.outputs.version }}" -o "$BINARY_NAME" ./cmd/github-copilot-svcs
# Make the binary executable (important for Unix systems)
chmod +x "$BINARY_NAME"
# Gzip the binary
GZ_BINARY_NAME="$BINARY_NAME.gz"
gzip -c "$BINARY_NAME" > "$GZ_BINARY_NAME"
echo "Built and gzipped binary: $GZ_BINARY_NAME"
ls -la "$GZ_BINARY_NAME"
- name: Upload Release Asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.release.outputs.version }}
files: ./github-copilot-svcs-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.suffix }}.gz
body: |
## Changes in ${{ needs.release.outputs.version }}
Auto-generated release from main branch.
### Downloads
- Linux AMD64: `github-copilot-svcs-linux-amd64.gz`
- Linux ARM64: `github-copilot-svcs-linux-arm64.gz`
- macOS AMD64: `github-copilot-svcs-darwin-amd64.gz`
- macOS ARM64: `github-copilot-svcs-darwin-arm64.gz`
- Windows AMD64: `github-copilot-svcs-windows-amd64.exe.gz`
- Windows ARM64: `github-copilot-svcs-windows-arm64.exe.gz`
docker:
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-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: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ needs.release.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release.outputs.version }}
type=semver,pattern={{major}},value=${{ needs.release.outputs.version }}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ needs.release.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max