Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@ on:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Install dependencies
run: go mod download

- name: Run tests
run: go test ./...

compile:
needs: test
if: success()

runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -22,3 +42,43 @@ jobs:

- name: Compile binary
run: go build -o myapp

build:
# Specify the OS for the runner
runs-on: ubuntu-latest

# Grant write permissions to access repository contents and GitHub Container Registry
permissions:
contents: write
packages: write

# Run this job only after the 'compile' job is completed successfully
needs: compile
if: success()

steps:
# Step 1: Checkout the repository code
- name: Checkout code
uses: actions/checkout@v4

# Step 2: Set up the Go environment (Go 1.22)
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'

# Step 3: Log in to GitHub Container Registry (GHCR) using the GitHub Actions token
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }} # GitHub username (actor triggering the workflow)
password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided GitHub token

# Step 4: Build the Docker image and tag it with the repository name and 'latest'
- name: Build Docker image
run: docker build -t ghcr.io/${{ github.repository }}:latest .

# Step 5: Push the Docker image to GitHub Container Registry
- name: Push Docker image
run: docker push ghcr.io/${{ github.repository }}:latest