diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml new file mode 100644 index 0000000..2dd6ba9 --- /dev/null +++ b/.github/workflows/build-and-release.yml @@ -0,0 +1,117 @@ +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: + GH_PAT: ${{ secrets.GH_PAT }} + run: | + TAG_NAME="v$VERSION" + RELEASE_NAME="Release v$VERSION" + API_URL="https://api.github.com/repos/LMaxence/gookme/releases" + RESPONSE=$(curl -s -X POST -H "X-GitHub-Api-Version: 2022-11-28" -H "Authorization: Bearer $GH_PAT" $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: + GH_PAT: ${{ secrets.GH_PAT }} + UPLOAD_URL: ${{ env.UPLOAD_URL }} + run: | + # for FILE in build/*/*; do + # FILENAME=$(basename $FILE) + # curl -s -X POST \ + # -H "Accept: application/vnd.github+json" \ + # -H "X-GitHub-Api-Version: 2022-11-28" \ + # -H "Authorization: Bearer $GH_PAT" \ + # -H "Content-Type: application/octet-stream" \ + # "$UPLOAD_URL?name=$FILENAME" \ + # --data-binary "@$FILE" + # done + ls build + ls build/darwin + ls build/linux + ls build/windows \ No newline at end of file diff --git a/.github/workflows/tag-version.yml b/.github/workflows/tag-version.yml index 05f69aa..30ff4f6 100644 --- a/.github/workflows/tag-version.yml +++ b/.github/workflows/tag-version.yml @@ -4,6 +4,8 @@ on: push: branches: - main + paths: + - 'packages/meta/version.go' jobs: tag: @@ -11,7 +13,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: token: ${{ secrets.GH_PAT }} diff --git a/Makefile b/Makefile index 90c3715..2785baf 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file +build: build/darwin build/linux build/windows \ No newline at end of file