From 1a71abf7f8e849d7384ff9879decfb1bb676e90c Mon Sep 17 00:00:00 2001 From: Thorsten Klein Date: Tue, 6 Aug 2024 20:28:28 +0200 Subject: [PATCH] chore: workflow --- .github/workflows/main.yml | 68 ++++++++++++++++++++++++++++++++++---- Makefile | 3 +- scripts/cross-build.sh | 9 ----- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bd6facd..02e305d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,7 @@ name: Release on: + workflow_dispatch: push: tags: - "v*" @@ -9,14 +10,13 @@ env: GO_VERSION: "1.22.x" jobs: - release-github: - name: Build & Release Binaries + build: + name: Build Binaries runs-on: ${{ matrix.os }} strategy: matrix: os: [ ubuntu-22.04, macos-latest ] steps: - # Setup - uses: actions/checkout@v4 - name: Setup Go environment uses: actions/setup-go@v5 @@ -33,10 +33,65 @@ jobs: echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)" brew install mingw-w64 - # Go Build - name: Build Binary run: make build-cross - # Create Git Release + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os }}-artifacts + path: dist/* + retention-days: 1 + if-no-files-found: error + + collect-artifacts: + name: Collect Artifacts and Generate Checksums + runs-on: ubuntu-22.04 + needs: build + steps: + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + name: ubuntu-22.04-artifacts + path: dist + merge-multiple: true + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + name: macos-latest-artifacts + path: dist + merge-multiple: true + - name: Calculate Checksums + run: | + cd dist + sha256sum knowledge-* > checksums.txt + - name: Upload Checksums + uses: actions/upload-artifact@v4 + with: + name: checksums + path: dist/checksums.txt + + release: + name: Create Release + runs-on: ubuntu-22.04 + needs: collect-artifacts + steps: + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + name: ubuntu-22.04-artifacts + path: dist + merge-multiple: true + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + name: macos-latest-artifacts + path: dist + - name: Download Checksums + uses: actions/download-artifact@v4 + with: + name: checksums + path: dist + merge-multiple: true - name: Extract Tag from Ref if: startsWith(github.ref, 'refs/tags/') id: tag @@ -53,7 +108,8 @@ jobs: with: allowUpdates: true artifactErrorsFailBuild: true - artifacts: dist/* + artifacts: | + dist/* makeLatest: ${{ steps.semver.outputs.prerelease == '' }} generateReleaseNotes: true prerelease: ${{ steps.semver.outputs.prerelease != '' }} diff --git a/Makefile b/Makefile index d03439c..410059e 100644 --- a/Makefile +++ b/Makefile @@ -69,5 +69,4 @@ validate-docs: ;fi gen-checksum: - $(eval ARTIFACTS_TO_PUBLISH := $(shell ls dist/*)) - $$(sha256sum $(ARTIFACTS_TO_PUBLISH) > dist/checksums.txt) \ No newline at end of file + $$(cd dist && sha256sum knowledge-* > checksums.txt) \ No newline at end of file diff --git a/scripts/cross-build.sh b/scripts/cross-build.sh index 39f5055..e691218 100755 --- a/scripts/cross-build.sh +++ b/scripts/cross-build.sh @@ -6,15 +6,9 @@ LD_FLAGS="-s -w -X github.com/gptscript-ai/knowledge/version.Version=${GIT_TAG}" export CGO_ENABLED=1 -mkdir -p dist/ -touch dist/checksums.txt - if [ "$(go env GOOS)" = "linux" ]; then # Linux: amd64, arm64 GOARCH=amd64 go build -o dist/knowledge-linux-amd64 -tags "${GO_TAGS}" -ldflags "${LD_FLAGS}\" -extldflags \"-static\" " . - - # Checksum - sha256sum dist/knowledge-linux-amd64 >> dist/checksums.txt else # Windows: amd64 @@ -23,7 +17,4 @@ else # Darwin: amd64, arm64 GOARCH=amd64 go build -o dist/knowledge-darwin-amd64 -tags "${GO_TAGS}" -ldflags "${LD_FLAGS}" . GOARCH=arm64 go build -o dist/knowledge-darwin-arm64 -tags "${GO_TAGS}" -ldflags "${LD_FLAGS}" . - - # Checksum - shasum -a 256 dist/knowledge-windows-amd64 dist/knowledge-darwin-amd64 dist/knowledge-darwin-arm64 >> dist/checksums.txt fi