Skip to content

Commit

Permalink
feat: add release script
Browse files Browse the repository at this point in the history
  • Loading branch information
LMaxence committed Aug 23, 2024
1 parent 257ca98 commit 2d18f12
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 17 deletions.
112 changes: 112 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Build and Release

on:
push:
branches:
- main

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
include:
- os: ubuntu-latest
platform: linux
arch: amd64
- os: ubuntu-latest
platform: linux
arch: arm64
- os: macos-latest
platform: darwin
arch: amd64
- os: macos-latest
platform: darwin
arch: arm64
- os: windows-latest
platform: windows
arch: amd64
- os: windows-latest
platform: windows
arch: arm64

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22.4'

- name: Install dependencies
run: go mod download

- name: Build project for ${{matrix.platform}} ${{matrix.arch}}
run: make build/${{matrix.platform}}/gookme-${{matrix.platform}}-${{matrix.arch}}

- name: Upload build artifacts for ${{matrix.platform}} ${{matrix.arch}}
uses: actions/upload-artifact@v4
with:
name: build-artifacts-${{ matrix.platform }}-${{ matrix.arch }}
path: build/${{ matrix.platform }}/

merge:
runs-on: ubuntu-latest
needs: build
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: build-artifacts
delete-merged: true
retention-days: 1
compression-level: 9

release:
needs: merge
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: build

- name: Extract VERSION
id: extract_version
run: |
VERSION=$(grep -oP 'VERSION\s*=\s*"\K[^"]+' packages/meta/version.go)
echo "VERSION=$VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME="v$VERSION"
RELEASE_NAME="Release v$VERSION"
API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/releases"
RESPONSE=$(curl -s -X POST -H "X-GitHub-Api-Version: 2022-11-28" -H "Authorization: Bearer $GITHUB_TOKEN" $API_URL -d "{ \"tag_name\": \"$TAG_NAME\", \"name\": \"$RELEASE_NAME\", \"draft\": false, \"prerelease\": false }")
UPLOAD_URL=$(echo $RESPONSE | jq -r .upload_url | sed -e "s/{?name,label}//")
echo "UPLOAD_URL=$UPLOAD_URL" >> $GITHUB_ENV
- name: Upload Release Assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPLOAD_URL: ${{ env.UPLOAD_URL }}
run: |
for FILE in build/*; do
FILENAME=$(basename $FILE)
curl -s -X POST \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @$FILE \
"$UPLOAD_URL?name=$FILENAME"
done
4 changes: 3 additions & 1 deletion .github/workflows/tag-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ on:
push:
branches:
- main
paths:
- 'packages/meta/version.go'

jobs:
tag:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }}

Expand Down
38 changes: 22 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,34 @@ schemas: assets/schemas/global.schema.json assets/schemas/hooks.schema.json asse

hooks: .git/hooks/pre-commit .git/hooks/commit-msg

build/gookme-darwin-amd64:
build/darwin/gookme-darwin-amd64:
@echo "Building gookme for darwin/amd64"
GOOS=darwin GOARCH=amd64 go build -o build/gookme-darwin-amd64 ./cmd/cli
GOOS=darwin GOARCH=amd64 go build -o build/darwin/gookme-darwin-amd64 ./cmd/cli

build/gookme-linux-amd64:
@echo "Building gookme for linux/amd64"
GOOS=linux GOARCH=amd64 go build -o build/gookme-linux-amd64 ./cmd/cli
build/darwin/gookme-darwin-arm64:
@echo "Building gookme for darwin/arm64"
GOOS=darwin GOARCH=arm64 go build -o build/darwin/gookme-darwin-arm64 ./cmd/cli

build/gookme-windows-amd64:
@echo "Building gookme for windows/amd64"
GOOS=windows GOARCH=amd64 go build -o build/gookme-windows-amd64.exe ./cmd/cli
build/darwin: build/darwin/gookme-darwin-amd64 build/darwin/gookme-darwin-arm64

build/gookme-darwin-arm64:
@echo "Building gookme for darwin/arm64"
GOOS=darwin GOARCH=arm64 go build -o build/gookme-darwin-arm64 ./cmd/cli
build/linux/gookme-linux-amd64:
@echo "Building gookme for linux/amd64"
GOOS=linux GOARCH=amd64 go build -o build/linux/gookme-linux-amd64 ./cmd/cli

build/gookme-linux-arm64:
build/linux/gookme-linux-arm64:
@echo "Building gookme for linux/arm64"
GOOS=linux GOARCH=arm64 go build -o build/gookme-linux-arm64 ./cmd/cli
GOOS=linux GOARCH=arm64 go build -o build/linux/gookme-linux-arm64 ./cmd/cli

build/gookme-windows-arm64:
build/linux: build/linux/gookme-linux-amd64 build/linux/gookme-linux-arm64

build/windows/gookme-windows-amd64:
@echo "Building gookme for windows/amd64"
GOOS=windows GOARCH=amd64 go build -o build/windows/gookme-windows-amd64.exe ./cmd/cli

build/windows/gookme-windows-arm64:
@echo "Building gookme for windows/arm64"
GOOS=windows GOARCH=arm64 go build -o build/gookme-windows-arm64.exe ./cmd/cli
GOOS=windows GOARCH=arm64 go build -o build/windows/gookme-windows-arm64.exe ./cmd/cli

build/windows: build/windows/gookme-windows-amd64 build/windows/gookme-windows-arm64

build: build/gookme-darwin-amd64 build/gookme-linux-amd64 build/gookme-windows-amd64 build/gookme-darwin-arm64 build/gookme-linux-arm64 build/gookme-windows-arm64
build: build/darwin build/linux build/windows

0 comments on commit 2d18f12

Please sign in to comment.