Skip to content

Commit dfcc7ad

Browse files
committed
BUILD/MAJOR: ci: add github workflows
1 parent f90c11a commit dfcc7ad

File tree

8 files changed

+556
-0
lines changed

8 files changed

+556
-0
lines changed

.github/stale.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Number of days of inactivity before an issue becomes stale
2+
daysUntilStale: 30
3+
# Number of days of inactivity before a stale issue is closed
4+
daysUntilClose: 30
5+
# Issues with these labels will never be considered stale
6+
exemptLabels:
7+
- enhancement
8+
- bug
9+
- documentation
10+
- hold-open
11+
# Label to use when marking an issue as stale
12+
staleLabel: stale
13+
# Comment to post when marking an issue as stale. Set to `false` to disable
14+
markComment: >
15+
This issue has been automatically marked as stale because it has not had
16+
recent activity. It will be closed if no further activity occurs. Thank you
17+
for your contributions.
18+
# Comment to post when closing a stale issue. Set to `false` to disable
19+
closeComment: false

.github/workflows/.goreleaser.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: goreleaser
2+
on:
3+
push:
4+
tags:
5+
- "*"
6+
jobs:
7+
goreleaser:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
with:
13+
# we have to fetch all history to be able to generate the release note. c.f. https://goreleaser.com/ci/actions/.
14+
fetch-depth: 0
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: "go.mod"
19+
check-latest: true
20+
- name: Run GoReleaser
21+
uses: goreleaser/goreleaser-action@v4
22+
with:
23+
distribution: goreleaser
24+
version: 1.17.1
25+
args: release --clean
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/actions.yml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: CI
2+
on: [push, pull_request]
3+
jobs:
4+
check:
5+
if: ${{ github.event_name == 'pull_request' }}
6+
name: HAProxy check commit message
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Check out code
10+
uses: actions/checkout@v4
11+
- name: Set up Go
12+
uses: actions/setup-go@v5
13+
with:
14+
go-version-file: 'go.mod'
15+
id: go
16+
- name: Install Task
17+
uses: go-task/setup-task@v1
18+
with:
19+
version: 3.x
20+
repo-token: ${{ secrets.GITHUB_TOKEN }}
21+
- name: commit-policy
22+
run: task check-commit
23+
generate-doc:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Check out code
27+
uses: actions/checkout@v4
28+
- name: Set up Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version-file: 'go.mod'
32+
id: go
33+
- name: Install Task
34+
uses: go-task/setup-task@v1
35+
with:
36+
version: 3.x
37+
repo-token: ${{ secrets.GITHUB_TOKEN }}
38+
- name: prepare taskfile
39+
run: "sed -i 's/internal: true/internal: false/g' taskfile/generate.yml"
40+
- name: generating documentation
41+
run: task generate
42+
- name: reset taskfile
43+
run: "sed -i 's/internal: false/internal: true/g' taskfile/generate.yml"
44+
- name: changes
45+
run: test -z "$(git diff 2> /dev/null)" || exit "Documentation is not generated, issue \`task ci\` and commit the result"
46+
- name: untracked files
47+
run: test -z "$(git ls-files --others --exclude-standard 2> /dev/null)" || exit "Documentation created untracked files, cannot proceed"
48+
generate-code:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Check out code
52+
uses: actions/checkout@v4
53+
- name: Set up Go
54+
uses: actions/setup-go@v5
55+
with:
56+
go-version-file: 'go.mod'
57+
id: go
58+
- name: Install Task
59+
uses: go-task/setup-task@v1
60+
with:
61+
version: 3.x
62+
repo-token: ${{ secrets.GITHUB_TOKEN }}
63+
- name: prepare taskfile
64+
run: "sed -i 's/internal: true/internal: false/g' taskfile/generate.yml"
65+
- name: generating code
66+
run: task controller-gen
67+
- name: reset taskfile
68+
run: "sed -i 's/internal: false/internal: true/g' taskfile/generate.yml"
69+
- name: changes
70+
run: test -z "$(git diff 2> /dev/null)" || exit "code generation is not run, issue \`task ci\` and commit the result"
71+
- name: untracked files
72+
run: test -z "$(git ls-files --others --exclude-standard 2> /dev/null)" || exit "Documentation created untracked files, cannot proceed"
73+
tidy:
74+
name: go mod tidy
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Check out code
78+
uses: actions/checkout@v4
79+
- name: Set up Go
80+
uses: actions/setup-go@v5
81+
with:
82+
go-version-file: "go.mod"
83+
check-latest: true
84+
- name: tidy
85+
run: go mod tidy
86+
- name: changes
87+
run: test -z "$(git diff 2> /dev/null)" || exit "Go modules not tidied, issue \`go mod tidy\` and commit the result"
88+
gofumpt:
89+
name: gofumpt
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Check out code
93+
uses: actions/checkout@v4
94+
- name: Set up Go
95+
uses: actions/setup-go@v5
96+
with:
97+
go-version-file: 'go.mod'
98+
id: go
99+
- name: Install Task
100+
uses: go-task/setup-task@v1
101+
with:
102+
version: 3.x
103+
repo-token: ${{ secrets.GITHUB_TOKEN }}
104+
- name: prepare taskfile
105+
run: "sed -i 's/internal: true/internal: false/g' taskfile/generate.yml"
106+
- name: tidy
107+
run: task format
108+
- name: reset taskfile
109+
run: "sed -i 's/internal: false/internal: true/g' taskfile/generate.yml"
110+
- name: changes
111+
run: test -z "$(git diff 2> /dev/null)" || exit "Go code not formatted, issue \`make gofumpt\` and commit the result"
112+
lint:
113+
name: golangci-lint
114+
needs: ["generate", "tidy"]
115+
runs-on: ubuntu-latest
116+
steps:
117+
- name: Check out code
118+
uses: actions/checkout@v4
119+
- name: Set up Go
120+
uses: actions/setup-go@v5
121+
with:
122+
go-version-file: 'go.mod'
123+
id: go
124+
- name: Install Task
125+
uses: go-task/setup-task@v1
126+
with:
127+
version: 3.x
128+
repo-token: ${{ secrets.GITHUB_TOKEN }}
129+
- name: reset taskfile
130+
run: "sed -i 's/internal: false/internal: true/g' taskfile/generate.yml"
131+
- name: Lint
132+
run: |
133+
task lint
134+
- name: reset taskfile
135+
run: "sed -i 's/internal: false/internal: true/g' taskfile/generate.yml"
136+
build:
137+
name: build
138+
runs-on: ubuntu-latest
139+
needs: ["lint"]
140+
steps:
141+
- name: Check out code
142+
uses: actions/checkout@v4
143+
- name: Set up Go
144+
uses: actions/setup-go@v5
145+
with:
146+
go-version-file: 'go.mod'
147+
id: go
148+
- name: Get dependencies
149+
run: |
150+
go mod tidy
151+
- name: Build
152+
run: |
153+
go build -v .
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Build on release and push to Docker Hub
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
jobs:
7+
main:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: read
11+
packages: write
12+
env:
13+
DOCKER_PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
14+
DOCKER_IMAGE: haproxytech/haproxy-unified-gateway
15+
LATEST_BRANCH: "dev"
16+
steps:
17+
- name: Login to Docker Hub
18+
id: login_docker
19+
uses: docker/login-action@v1
20+
with:
21+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
22+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
23+
24+
- name: Login to Container Registry
25+
id: login_ghcr
26+
uses: docker/login-action@v1
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v1
34+
35+
- name: Set up Docker Buildx
36+
id: buildx
37+
uses: docker/setup-buildx-action@v1
38+
39+
- name: Cache Docker layers
40+
uses: actions/cache@v4
41+
with:
42+
path: /tmp/.buildx-cache
43+
key: ${{ runner.os }}-buildx-${{ github.sha }}
44+
restore-keys: |
45+
${{ runner.os }}-buildx-
46+
47+
- name: Check out repo
48+
id: checkout
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
53+
- name: Prepare env variables
54+
id: env
55+
run: |
56+
echo "BUILD_BRANCH=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's:^v::g' | cut -d. -f-2)" >> $GITHUB_ENV
57+
echo "BUILD_VER=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's:^v::g')" >> $GITHUB_ENV
58+
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
59+
echo "GIT_SHA=$(git rev-parse --short HEAD | cut -c1-7)" >> $GITHUB_ENV
60+
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV
61+
echo "LATEST_BRANCH=$(curl -sfSL 'https://raw.githubusercontent.com/haproxytech/haproxy-unified-gateway/master/documentation/doc.yaml' 2>/dev/null | awk -F: '/^active_version/ {gsub(/^ /,"",$2); print $2}' || echo $LATEST_BRANCH)" >> $GITHUB_ENV
62+
63+
- name: Build and push latest stable branch
64+
if: ${{ env.BUILD_BRANCH == env.LATEST_BRANCH }}
65+
id: docker_build_latest
66+
uses: docker/build-push-action@v2
67+
with:
68+
context: .
69+
file: build/Dockerfile
70+
builder: ${{ steps.buildx.outputs.name }}
71+
platforms: ${{ env.DOCKER_PLATFORMS }}
72+
push: true
73+
labels: |
74+
org.opencontainers.image.authors=${{ github.repository_owner }}
75+
org.opencontainers.image.created=${{ env.BUILD_DATE }}
76+
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
77+
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
78+
org.opencontainers.image.revision=${{ env.GIT_SHA }}
79+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
80+
org.opencontainers.image.version=${{ env.BUILD_VER }}
81+
tags: |
82+
${{ env.DOCKER_IMAGE }}:latest
83+
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_BRANCH }}
84+
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }}
85+
ghcr.io/${{ github.repository }}:latest
86+
ghcr.io/${{ github.repository }}:${{ env.BUILD_BRANCH }}
87+
ghcr.io/${{ github.repository }}:${{ env.BUILD_VER }}
88+
cache-from: type=local,src=/tmp/.buildx-cache
89+
cache-to: type=local,dest=/tmp/.buildx-cache-new
90+
91+
- name: Build and push everything else
92+
if: ${{ env.BUILD_BRANCH != env.LATEST_BRANCH }}
93+
id: docker_build_regular
94+
uses: docker/build-push-action@v2
95+
with:
96+
context: .
97+
file: build/Dockerfile
98+
builder: ${{ steps.buildx.outputs.name }}
99+
platforms: ${{ env.DOCKER_PLATFORMS }}
100+
push: true
101+
labels: |
102+
org.opencontainers.image.authors=${{ github.repository_owner }}
103+
org.opencontainers.image.created=${{ env.BUILD_DATE }}
104+
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
105+
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
106+
org.opencontainers.image.revision=${{ env.GIT_SHA }}
107+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
108+
org.opencontainers.image.version=${{ env.BUILD_VER }}
109+
tags: |
110+
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_BRANCH }}
111+
${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }}
112+
ghcr.io/${{ github.repository }}:${{ env.BUILD_BRANCH }}
113+
ghcr.io/${{ github.repository }}:${{ env.BUILD_VER }}
114+
cache-from: type=local,src=/tmp/.buildx-cache
115+
cache-to: type=local,dest=/tmp/.buildx-cache-new
116+
117+
- name: Move cache
118+
run: |
119+
rm -rf /tmp/.buildx-cache
120+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Update Docker Hub description
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- README.md
8+
workflow_dispatch:
9+
jobs:
10+
main:
11+
runs-on: ubuntu-latest
12+
env:
13+
DOCKER_IMAGE: haproxytech/haproxy-unified-gateway
14+
steps:
15+
- name: Check out repo
16+
id: checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Update Docker Hub description
20+
id: description
21+
uses: peter-evans/dockerhub-description@v2
22+
with:
23+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
24+
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
25+
repository: ${{ env.DOCKER_IMAGE }}
26+
short-description: ${{ github.event.repository.description }}

0 commit comments

Comments
 (0)