Change Config File from toml to .env #20
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: Go Build | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*.*.*' | |
env: | |
ARTIFACT_NAME: inventory-app # Define the artifact name here | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
os: [linux, darwin, windows] | |
arch: [amd64, arm64] | |
steps: | |
# Step 1: Check out the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Step 2: Set up Go environment | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.23' | |
# Step 3: Install dependencies | |
- name: Install dependencies | |
working-directory: ./backend | |
run: go mod tidy | |
# Step 4: Build the Go project for each OS/Arch combination | |
- name: Build | |
working-directory: ./backend | |
run: | | |
# Build binary for the OS/Arch combination, use the ARTIFACT_NAME variable | |
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o ${{ env.ARTIFACT_NAME }}-${{ matrix.os }}-${{ matrix.arch }} main.go | |
# Step 5: Upload the binaries as artifacts | |
- name: Upload release binary | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.ARTIFACT_NAME }}-${{ matrix.os }}-${{ matrix.arch }} | |
path: ./backend/${{ env.ARTIFACT_NAME }}-${{ matrix.os }}-${{ matrix.arch }} | |
release: | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
# Step 1: Check out the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Step 2: Download all artifacts | |
- name: Download all artifacts | |
uses: actions/download-artifact@v3 | |
# Step 3: Rename Windows binaries to add .exe extension | |
- name: Rename Windows Binaries | |
run: | | |
mv ${{ env.ARTIFACT_NAME }}-windows-amd64/${{ env.ARTIFACT_NAME }}-windows-amd64 ${{ env.ARTIFACT_NAME }}-windows-amd64/${{ env.ARTIFACT_NAME }}-windows-amd64.exe | |
mv ${{ env.ARTIFACT_NAME }}-windows-arm64/${{ env.ARTIFACT_NAME }}-windows-arm64 ${{ env.ARTIFACT_NAME }}-windows-arm64/${{ env.ARTIFACT_NAME }}-windows-arm64.exe | |
# Step 4: Upload the binaries to the release (use variable for artifact name) | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
artifacts: | | |
${{ env.ARTIFACT_NAME }}-linux-amd64/${{ env.ARTIFACT_NAME }}-linux-amd64 | |
${{ env.ARTIFACT_NAME }}-linux-arm64/${{ env.ARTIFACT_NAME }}-linux-arm64 | |
${{ env.ARTIFACT_NAME }}-darwin-amd64/${{ env.ARTIFACT_NAME }}-darwin-amd64 | |
${{ env.ARTIFACT_NAME }}-darwin-arm64/${{ env.ARTIFACT_NAME }}-darwin-arm64 | |
${{ env.ARTIFACT_NAME }}-windows-amd64/${{ env.ARTIFACT_NAME }}-windows-amd64.exe | |
${{ env.ARTIFACT_NAME }}-windows-arm64/${{ env.ARTIFACT_NAME }}-windows-arm64.exe | |
tag: ${{ github.ref_name }} | |
name: Release ${{ github.ref_name }} | |
body: | | |
Cross-compiled binaries for multiple platforms. | |
draft: false | |
prerelease: false |