-
Notifications
You must be signed in to change notification settings - Fork 138
84 lines (66 loc) · 2.08 KB
/
deploy.yaml
File metadata and controls
84 lines (66 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Build CI/CD
on:
push:
branches:
- 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
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: 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