-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,86 @@ | ||
name: Build and Release | ||
name: Build and Publish Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' # Match version tags (e.g., v1.0.0) | ||
|
||
|
||
# Permission can be added at job level or workflow level | ||
permissions: | ||
contents: write # This is required to create/push the new git tag | ||
- 'v*' # Trigger on version tags (v1.0, v2.0, etc.) | ||
|
||
jobs: | ||
build: | ||
name: Build for all architectures | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
goos: [linux, darwin, windows] | ||
goarch: [amd64, arm64] | ||
binary: [server, client] | ||
os: [linux, windows, darwin] | ||
arch: [amd64, arm64] | ||
|
||
steps: | ||
# Checkout the repository | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
# Setup Go environment | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22.2' | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.22' | ||
|
||
# Build the binaries | ||
- name: Build binaries | ||
run: | | ||
mkdir -p dist | ||
cd cmd/${{ matrix.binary }} | ||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o ../../dist/gordafarid-${{ matrix.binary }}-${{ matrix.goos }}-${{ matrix.goarch }} | ||
- name: Build binaries | ||
env: | ||
GOOS: ${{ matrix.os }} | ||
GOARCH: ${{ matrix.arch }} | ||
run: | | ||
mkdir -p bin/${{ matrix.os }}_${{ matrix.arch }} | ||
echo "Building for OS: $GOOS, ARCH: $GOARCH" | ||
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o bin/${{ matrix.os }}_${{ matrix.arch }}/client ./cmd/client | ||
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o bin/${{ matrix.os }}_${{ matrix.arch }}/server ./cmd/server | ||
# Upload the binaries as artifacts | ||
- name: Upload server binaries | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: binaries-server | ||
path: dist/gordafarid-server-* | ||
- name: List binaries | ||
run: ls -R bin/ | ||
|
||
- name: Upload client binaries | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: binaries-client | ||
path: dist/gordafarid-client-* | ||
- name: Extract tag name | ||
id: extract_tag | ||
run: echo "TAG_NAME=$(echo $GITHUB_REF | sed 's/refs\/tags\///')" >> $GITHUB_ENV | ||
|
||
release: | ||
name: Create GitHub Release | ||
runs-on: ubuntu-latest | ||
needs: build | ||
permissions: | ||
contents: write # Ensure this is set for creating releases | ||
|
||
steps: | ||
# Checkout the repository | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Rename and Prepare Files for Release | ||
run: | | ||
BASE_NAME="gordafarid" | ||
# Rename binaries to the specified format | ||
if [[ "${{ matrix.os }}" == "windows" ]]; then | ||
mv bin/${{ matrix.os }}_${{ matrix.arch }}/client bin/${{ matrix.os }}_${{ matrix.arch }}/${BASE_NAME}-client-${TAG_NAME}-${{ matrix.os }}-${{ matrix.arch }}.exe | ||
mv bin/${{ matrix.os }}_${{ matrix.arch }}/server bin/${{ matrix.os }}_${{ matrix.arch }}/${BASE_NAME}-server-${TAG_NAME}-${{ matrix.os }}-${{ matrix.arch }}.exe | ||
else | ||
mv bin/${{ matrix.os }}_${{ matrix.arch }}/client bin/${{ matrix.os }}_${{ matrix.arch }}/${BASE_NAME}-client-${TAG_NAME}-${{ matrix.os }}-${{ matrix.arch }} | ||
mv bin/${{ matrix.os }}_${{ matrix.arch }}/server bin/${{ matrix.os }}_${{ matrix.arch }}/${BASE_NAME}-server-${TAG_NAME}-${{ matrix.os }}-${{ matrix.arch }} | ||
fi | ||
# Create GitHub release | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref_name }} | ||
release_name: Release ${{ github.ref_name }} | ||
draft: false | ||
prerelease: false | ||
- name: List files after renaming | ||
run: ls -R bin/ | ||
|
||
# Upload the server binaries to the release | ||
- name: Upload Server Binaries | ||
uses: actions/upload-release-asset@v1 | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: dist/gordafarid-server-* | ||
asset_name: gordafarid-server-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} | ||
asset_content_type: application/octet-stream | ||
- name: Create GitHub Release | ||
id: create_release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
tag_name: ${{ env.TAG_NAME }} | ||
name: Release ${{ env.TAG_NAME }} | ||
body: | | ||
Binaries for ${{ env.TAG_NAME }} | ||
continue-on-error: true # Allows it to continue even if the release already exists | ||
|
||
# Upload the client binaries to the release | ||
- name: Upload Client Binaries | ||
uses: actions/upload-release-asset@v1 | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: dist/gordafarid-client-* | ||
asset_name: gordafarid-client-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }} | ||
asset_content_type: application/octet-stream | ||
- name: Upload Release Assets | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
tag_name: ${{ env.TAG_NAME }} | ||
files: | | ||
bin/linux_amd64/gordafarid-client-${{ env.TAG_NAME }}-linux-amd64 | ||
bin/linux_amd64/gordafarid-server-${{ env.TAG_NAME }}-linux-amd64 | ||
bin/linux_arm64/gordafarid-client-${{ env.TAG_NAME }}-linux-arm64 | ||
bin/linux_arm64/gordafarid-server-${{ env.TAG_NAME }}-linux-arm64 | ||
bin/windows_amd64/gordafarid-client-${{ env.TAG_NAME }}-windows-amd64.exe | ||
bin/windows_amd64/gordafarid-server-${{ env.TAG_NAME }}-windows-amd64.exe | ||
bin/windows_arm64/gordafarid-client-${{ env.TAG_NAME }}-windows-arm64.exe | ||
bin/windows_arm64/gordafarid-server-${{ env.TAG_NAME }}-windows-arm64.exe | ||
bin/darwin_amd64/gordafarid-client-${{ env.TAG_NAME }}-darwin-amd64 | ||
bin/darwin_amd64/gordafarid-server-${{ env.TAG_NAME }}-darwin-amd64 | ||
bin/darwin_arm64/gordafarid-client-${{ env.TAG_NAME }}-darwin-arm64 | ||
bin/darwin_arm64/gordafarid-server-${{ env.TAG_NAME }}-darwin-arm64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters