-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (84 loc) · 2.6 KB
/
ci-cd.yaml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: CI/CD Pipeline
on:
push:
tags:
- 'v*.*.*'
pull_request:
branches: [ main ]
env:
GO_VERSION: 1.23
DOCKER_IMAGE: docker.io/raufzer/dz-jobs-api-docker
RAILWAY_SERVICE: dz-jobs-api
jobs:
test:
name: Test and Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Swagger
run: go install github.com/swaggo/swag/cmd/swag@latest
- name: Generate Swagger Docs
run: swag init -g cmd/server/main.go -o docs
- name: Run tests
run: go test -v ./...
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout 5m
- name: Security audit
run: go run golang.org/x/vuln/cmd/govulncheck@latest ./...
build-docker:
name: Build and Push Docker Image
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Extract version tag
id: extract_tag
run: |
# Extract the tag name from the Git reference (e.g., refs/tags/v1.1.5)
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "Extracted tag: $TAG_NAME"
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.DOCKER_IMAGE }}:${{ steps.extract_tag.outputs.tag_name }}
${{ env.DOCKER_IMAGE }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
name: Deploy to Railway
needs: build-docker
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Railway CLI
run: npm install -g @railway/cli
- name: Deploy to Railway
run: railway up --service ${{ secrets.RAILWAY_SERVICE_ID }} --detach
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}