chore(ci): add GitHub Actions workflow for release process
* Implement test and release jobs for versioned tags * Build binaries for multiple OS/architecture targets * Create release and upload assets to GitHub * Add release-version target in Makefile for version bumping
This commit is contained in:
57
.gitea/workflows/release.yml
Normal file
57
.gitea/workflows/release.yml
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test ./...
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: go vet ./...
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Build release binaries
|
||||||
|
run: |
|
||||||
|
VERSION="${GITHUB_REF_NAME}"
|
||||||
|
for target in "linux/amd64" "linux/arm64" "darwin/amd64" "darwin/arm64" "windows/amd64"; do
|
||||||
|
GOOS="${target%/*}"
|
||||||
|
GOARCH="${target#*/}"
|
||||||
|
EXT=""
|
||||||
|
[ "$GOOS" = "windows" ] && EXT=".exe"
|
||||||
|
NAME="unitdore-${GOOS}-${GOARCH}${EXT}"
|
||||||
|
GOOS="$GOOS" GOARCH="$GOARCH" go build \
|
||||||
|
-ldflags "-X main.version=${VERSION}" \
|
||||||
|
-o "$NAME" .
|
||||||
|
echo "Built $NAME"
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Create release and upload assets
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: unitdore-*
|
||||||
|
generate_release_notes: true
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "Launch Package",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
Makefile
14
Makefile
@@ -4,7 +4,7 @@ CONFIG_DIR := /etc/unitdore
|
|||||||
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||||
LDFLAGS := -ldflags "-X main.version=$(VERSION)"
|
LDFLAGS := -ldflags "-X main.version=$(VERSION)"
|
||||||
|
|
||||||
.PHONY: all build install uninstall test lint clean
|
.PHONY: all build install uninstall test lint clean release-version
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
@@ -40,6 +40,18 @@ lint:
|
|||||||
clean:
|
clean:
|
||||||
rm -f $(BINARY)
|
rm -f $(BINARY)
|
||||||
|
|
||||||
|
## release-version: bump patch version, tag, and push to trigger release workflow
|
||||||
|
release-version:
|
||||||
|
@CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
|
||||||
|
MAJOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'); \
|
||||||
|
MINOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'); \
|
||||||
|
PATCH=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'); \
|
||||||
|
NEXT="v$$MAJOR.$$MINOR.$$((PATCH + 1))"; \
|
||||||
|
echo "Current: $$CURRENT → Next: $$NEXT"; \
|
||||||
|
git tag -a "$$NEXT" -m "Release $$NEXT"; \
|
||||||
|
git push origin "$$NEXT"; \
|
||||||
|
echo "Pushed tag $$NEXT — release workflow triggered"
|
||||||
|
|
||||||
## help: show this help
|
## help: show this help
|
||||||
help:
|
help:
|
||||||
@grep -E '^## ' Makefile | sed 's/## / /'
|
@grep -E '^## ' Makefile | sed 's/## / /'
|
||||||
|
|||||||
Reference in New Issue
Block a user