generated from mrsimonemms/new
-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (151 loc) · 4.9 KB
/
build.yml
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Build
on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: write
packages: write
pull-requests: read
jobs:
commitlint:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch-depth is required
- uses: wagoid/commitlint-github-action@v5
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required for Toodaloo hook to work
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install dependencies
run: go install ./...
- name: go-vet
run: go vet -v ./...
- uses: pre-commit/[email protected]
build:
runs-on: ubuntu-latest
needs:
- commitlint
- test
outputs:
is_tag: ${{ steps.branch-name.outputs.is_tag }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required for goreleaser changelog to work correctly
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Build docs
run: |
npm ci
npm run docs:build
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get branch names
id: branch-name
uses: tj-actions/branch-names@v8
with:
strip_tag_prefix: v
- name: Generate Docker tag
id: docker
run: |
if [ "${{ steps.branch-name.outputs.is_tag }}" = "true" ];
then
# Latest tag
IMG_NAME="ghcr.io/${GITHUB_REPOSITORY,,}:latest"
# Tag name (usually vX.Y.Z)
IMG_NAME="${IMG_NAME},ghcr.io/${GITHUB_REPOSITORY,,}:${{ steps.branch-name.outputs.tag }}"
echo "image_name=${IMG_NAME}" >> "$GITHUB_OUTPUT"
echo "platforms=linux/amd64,linux/arm64,linux/arm/v7" >> "$GITHUB_OUTPUT"
echo "push=true" >> "$GITHUB_OUTPUT"
else
# Use branch naming convention
TAG="branch-${{ steps.branch-name.outputs.current_branch }}"
# Change "/" for "-"
TAG="${TAG//\//-}"
# Set to lowercase
TAG="${TAG,,}"
echo "image_name=ghcr.io/${GITHUB_REPOSITORY,,}:${TAG}" >> "$GITHUB_OUTPUT"
echo "platforms=linux/amd64" >> "$GITHUB_OUTPUT"
echo "push=${{ github.ref == 'refs/heads/main' }}" >> "$GITHUB_OUTPUT"
fi
if [ "${{ steps.branch-name.outputs.is_tag }}" = "true" ];
then
echo "version=${{ steps.branch-name.outputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "version=development" >> "$GITHUB_OUTPUT"
fi
echo "container_tagged_image=ghcr.io/${GITHUB_REPOSITORY,,}:${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
echo "commit_id=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
echo "gitRepo=github.com/${GITHUB_REPOSITORY}" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
build-args: |
GIT_COMMIT=${{ steps.docker.outputs.commit_id }}
GIT_REPO=${{ steps.docker.outputs.gitRepo }}
VERSION=${{ steps.docker.outputs.version }}
platforms: ${{ steps.docker.outputs.platforms }}
push: ${{ steps.docker.outputs.push }}
tags: ${{ steps.docker.outputs.image_name }},${{ steps.docker.outputs.container_tagged_image }}
- name: Set up Go
if: steps.branch-name.outputs.is_tag == 'true'
uses: actions/setup-go@v3
with:
go-version: '>=1.20.0'
- name: Run GoReleaser
if: steps.branch-name.outputs.is_tag == 'true'
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GIT_REPO: ${{ steps.docker.outputs.gitRepo }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload docs
uses: actions/upload-pages-artifact@v3
with:
path: 'docs/.vitepress/dist/'
deploy:
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.is_tag == 'true'
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4