ci: Refactor project workflows, build with goreleaser

- Add configuration files for `goreleaser.yml` and GitHub workflows
- Update Go version to `1.22.x`
- Adjust workflow names and triggers in `.github/workflows` folder
This commit is contained in:
moonD4rk 2024-07-15 22:33:18 +08:00 committed by ᴍᴏᴏɴD4ʀᴋ
parent 5dcf1e163b
commit 5ead3ba3c3
4 changed files with 85 additions and 120 deletions

View File

@ -1,4 +1,4 @@
name: build name: Build
on: on:
push: push:

View File

@ -1,135 +1,38 @@
name: Release name: Release
on: on:
workflow_dispatch: workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs: jobs:
build: goreleaser:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout source - name: Set up Go
uses: actions/checkout@v4
- name: Use Golang
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: "1.22.x" go-version: '1.22.x'
- name: Build with xgo - name: Check out code
uses: crazy-max/ghaction-xgo@v3 uses: actions/checkout@v4
with: with:
xgo_version: latest fetch-depth: 0
go_version: ${{ matrix.go_version }}
dest: build
prefix: hack-browser-data
pkg: cmd/hack-browser-data
targets: windows/amd64,windows/386,linux/386,linux/amd64,linux/arm,linux/arm64,darwin/amd64
# targets: windows/amd64,windows/386,darwin/amd64,linux/arm
v: true
x: false
race: false
ldflags: -s -w
buildmode: default
- name: Set Variable - name: Run GoReleaser
run: | uses: goreleaser/goreleaser-action@v6
echo "RELEASE_WIN32=hack-browser-data-${{ github.event.release.tag_name}}windows-32bit" >> $GITHUB_ENV with:
echo "RELEASE_WIN64=hack-browser-data-${{ github.event.release.tag_name}}windows-64bit" >> $GITHUB_ENV version: '~> v2'
echo "RELEASE_OSX=hack-browser-data-${{ github.event.release.tag_name}}osx-64bit" >> $GITHUB_ENV args: release --clean --draft
echo "RELEASE_LinuxARM=hack-browser-data-${{ github.event.release.tag_name}}linux-arm" >> $GITHUB_ENV
echo "RELEASE_Linux386=hack-browser-data-${{ github.event.release.tag_name}}linux-386" >> $GITHUB_ENV
echo "RELEASE_LinuxARM64=hack-browser-data-${{ github.event.release.tag_name}}linux-arm64" >> $GITHUB_ENV
echo "RELEASE_LinuxAMD64=hack-browser-data-${{ github.event.release.tag_name}}linux-amd64" >> $GITHUB_ENV
- name: Build zip
run: |
mv build/hack-browser-data-windows*386.exe "$RELEASE_WIN32".exe
mv build/hack-browser-data-windows*amd64.exe "$RELEASE_WIN64".exe
mv build/hack-browser-data-darwin-*amd64 "$RELEASE_OSX"
mv build/hack-browser-data-linux-*arm-* "$RELEASE_LinuxARM"
mv build/hack-browser-data-linux-*arm64 "$RELEASE_LinuxARM64"
mv build/hack-browser-data-linux-*386 "$RELEASE_Linux386"
mv build/hack-browser-data-linux-*amd64 "$RELEASE_LinuxAMD64"
zip "$RELEASE_WIN32".zip "$RELEASE_WIN32".exe
zip "$RELEASE_WIN64".zip "$RELEASE_WIN64".exe
zip "$RELEASE_OSX".zip "$RELEASE_OSX"
zip "$RELEASE_LinuxARM".zip "$RELEASE_LinuxARM"
zip "$RELEASE_Linux386".zip "$RELEASE_Linux386"
zip "$RELEASE_LinuxAMD64".zip "$RELEASE_LinuxAMD64"
zip "$RELEASE_LinuxARM64".zip "$RELEASE_Linux386"
- name: Create Release
id: create_release
uses: release-drafter/release-drafter@v6
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Release - Windows 64bit update_release_draft:
uses: actions/upload-release-asset@v1.0.2 needs: goreleaser
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v6
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.RELEASE_WIN64 }}.zip
asset_name: ${{ env.RELEASE_WIN64 }}.zip
asset_content_type: application/zip
- name: Upload Release - Windows 32bit
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.RELEASE_WIN32 }}.zip
asset_name: ${{ env.RELEASE_WIN32 }}.zip
asset_content_type: application/zip
- name: Upload Release - Darwin amd64
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.RELEASE_OSX }}.zip
asset_name: ${{ env.RELEASE_OSX }}.zip
asset_content_type: application/zip
- name: Upload Release - Linux arm
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.RELEASE_LinuxARM }}.zip
asset_name: ${{ env.RELEASE_LinuxARM }}.zip
asset_content_type: application/zip
- name: Upload Release - Linux amd64
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.RELEASE_LinuxAMD64 }}.zip
asset_name: ${{ env.RELEASE_LinuxAMD64 }}.zip
asset_content_type: application/zip
- name: Upload Release - Linux 386
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.RELEASE_Linux386 }}.zip
asset_name: ${{ env.RELEASE_Linux386 }}.zip
asset_content_type: application/zip
- name: Upload Release - Linux arm64
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_name: ${{ env.RELEASE_LinuxARM64 }}.zip
asset_content_type: application/zip
asset_path: ./${{ env.RELEASE_LinuxARM64 }}.zip

View File

@ -1,11 +1,13 @@
name: Tests
on: on:
pull_request: pull_request:
push: push:
branches: branches:
- main - main
- dev
workflow_dispatch: workflow_dispatch:
name: Tests
jobs: jobs:
test: test:
strategy: strategy:

60
.goreleaser.yml Normal file
View File

@ -0,0 +1,60 @@
version: 2
before:
hooks:
- go mod tidy
builds:
- id: "hack-browser-data"
main: ./cmd/hack-browser-data/main.go
binary: hack-browser-data
env:
- CGO_ENABLED=0
goos: [windows, linux, darwin]
goarch: [amd64, "386", arm, arm64]
ignore:
- goos: darwin
goarch: "386"
- goos: windows
goarch: "386"
- goos: windows
goarch: arm
flags:
- -trimpath
ldflags:
- -s -w
archives:
- id: "archive"
format: zip
builds: ["hack-browser-data"]
name_template: >-
hack-browser-data-
{{- if eq .Os "darwin" }}osx
{{- else if eq .Os "linux" }}linux
{{- else if eq .Os "windows" }}windows
{{- else }}{{ .Os }}{{ end }}-
{{- if eq .Arch "amd64" }}64bit
{{- else if eq .Arch "386" }}32bit
{{- else if eq .Arch "arm64" }}arm64
{{- else if eq .Arch "arm" }}arm
{{- else }}{{ .Arch }}{{ end }}
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^chore\\(deps\\):"
- "merge conflict"
- Merge pull request
- Merge remote-tracking branch
- Merge branch
- go mod tidy
checksum:
name_template: "checksums-v{{ .Version }}.txt"
algorithm: sha256
release:
prerelease: auto