#9-1: 98e5ff36362e9c0b79ec585980add46649ba197d by OLeonardoRodrigues #9
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 Publish" | |
run-name: "#${{ github.run_number }}-${{ github.run_attempt }}: ${{ github.sha }} by ${{ github.triggering_actor }}" | |
defaults: | |
run: | |
shell: bash | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
name: "Build Application Binary" | |
steps: | |
- name: "Checkout Code: REF ${{github.ref}}" | |
uses: actions/checkout@v4 | |
id: checkout | |
with: | |
ref: ${{github.ref}} | |
persist-credentials : true | |
fetch-depth: 1 | |
fetch-tags: false | |
clean: true | |
- name: "Set up QEMU for cross-platform builds" | |
uses: docker/setup-qemu-action@v3 | |
id: setup_qemu | |
- name: "Set up Docker Buildx" | |
uses: docker/setup-buildx-action@v3 | |
id: setup_docker_buildx | |
- name: "Restore Go Cache" | |
uses: actions/cache/restore@v4 | |
id: restore_go_cache | |
with: | |
path: | | |
~/.cache/go-build | |
~/go/pkg/mod | |
key: ${{ runner.os }}-go- | |
- name: "Setup Go Environment" | |
uses: actions/setup-go@v5.1.0 | |
id: setup_go | |
with: | |
go-version-file: "./go.mod" | |
cache: true | |
cache-dependency-path: "./go.sum" | |
- name: "Save Go Cache" | |
uses: actions/cache/save@v4 | |
id: save_go_cache | |
with: | |
path: | | |
~/.cache/go-build | |
~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
- name: "Run Build for ${{ runner.os }} ${{ runner.arch }}" | |
id: build | |
run: make build | |
- name: "Upload Build Artifact" | |
uses: actions/upload-artifact@v4.4.3 | |
id: upload_artifact | |
with: | |
name: "${{ github.run_number }}-${{ github.run_attempt }}-${{ github.sha }}-${{ runner.os }}-${{ runner.arch }}" | |
path: "./dist/app" | |
if-no-files-found: "error" | |
retention-days: 7 | |
compression-level: 9 | |
overwrite: true | |
include-hidden-files: false | |
- name: "Log in to GitHub Container Registry" | |
uses: docker/login-action@v3 | |
id: docker_login | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Restore Docker Cache" | |
uses: actions/cache/restore@v4 | |
id: restore_docker_cache | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-docker- | |
- name: "Sanitize Image Name" | |
id: sanitize_image_name | |
run: | | |
echo "image_name=$(echo ${{ github.repository_owner }}/${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
- name: "Build and Push Docker Image" | |
uses: docker/build-push-action@v6 | |
id: docker_build_push | |
with: | |
context: . | |
push: true | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max | |
tags: | | |
ghcr.io/$image_name:latest | |
ghcr.io/$image_name:${{ github.sha }} | |
- name: "Save Docker Cache" | |
uses: actions/cache/save@v4 | |
id: save_docker_cache | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-docker-${{ github.sha }} |