chore: release v0.1.0-alpha #2
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
name: Build and Release Application | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest # You can choose another runner if needed | |
steps: | |
# Checkout the code | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# Set up Go | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: '1.20' # Set this to the Go version you're using | |
# Cache Go modules to speed up builds | |
- name: Cache Go Modules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache/go-build | |
~/.go/pkg/mod | |
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.mod') }} | |
restore-keys: | | |
${{ runner.os }}-go-mod- | |
# Run the Makefile target to build for GitHub Actions | |
- name: Build for GitHub Actions | |
run: | | |
make build_gh_actions | |
# Fetch version from Makefile | |
- name: Get Version from Makefile | |
id: get_version | |
run: | | |
VERSION=$(make -s version | grep 'Version:' | cut -d ' ' -f 2) | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
release: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code again to create the release | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# Create a GitHub Release | |
- name: Create GitHub Release | |
id: create_release | |
uses: gh actions/create-release@v1 | |
with: | |
tag_name: ${{ env.VERSION }} | |
release_name: Release ${{ env.VERSION }} | |
body: | | |
A new release of the application is now available. | |
- Version: ${{ env.VERSION }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PRE_RELEASE: ${{ secrets.PRE_RELEASE }} # Set this environment variable in your GitHub repository settings | |
# Set the release as a pre-release if PRE_RELEASE is true | |
- name: Mark as Pre-release if necessary | |
if: ${{ env.PRE_RELEASE == 'true' }} | |
run: | | |
curl -X PATCH \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-d '{"prerelease": true}' \ | |
"https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.create_release.outputs.id }}" | |
# Upload the build artifacts to the release | |
- name: Upload Release Assets | |
uses: gh actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./$(APP_NAME)-linux-amd64 | |
asset_name: $(APP_NAME)-linux-amd64 | |
asset_content_type: application/octet-stream | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Windows Release Asset | |
uses: gh actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./$(APP_NAME)-windows-amd64 | |
asset_name: $(APP_NAME)-windows-amd64 | |
asset_content_type: application/octet-stream | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Optionally, upload other assets like arm64 if needed | |
- name: Upload ARM64 Release Asset | |
uses: gh actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./$(APP_NAME)-linux-arm64 | |
asset_name: $(APP_NAME)-linux-arm64 | |
asset_content_type: application/octet-stream | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |