Skip to content

Commit cdf4e23

Browse files
committed
add github actions
1 parent cbc9ab7 commit cdf4e23

File tree

3 files changed

+266
-0
lines changed

3 files changed

+266
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @pluralsh/server

.github/workflows/ci.yaml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
env:
10+
GOPATH: /home/runner/go/
11+
GOPROXY: "https://proxy.golang.org"
12+
REGISTRY_IMAGE: pluralsh/pr-governance-webhook
13+
jobs:
14+
build:
15+
name: Build
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-go@v5
20+
with:
21+
go-version-file: go.mod
22+
check-latest: true
23+
- run: PATH=$PATH:$GOPATH/bin make build
24+
test:
25+
name: Unit test
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: actions/setup-go@v5
30+
with:
31+
go-version-file: go.mod
32+
check-latest: true
33+
- run: PATH=$PATH:$GOPATH/bin make test
34+
lint:
35+
name: Lint
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: actions/setup-go@v5
40+
with:
41+
go-version-file: go.mod
42+
check-latest: true
43+
- uses: golangci/[email protected]
44+
with:
45+
version: v2.1.2
46+
build-image:
47+
name: Build image
48+
needs: [build, test]
49+
permissions:
50+
contents: 'read'
51+
id-token: 'write'
52+
packages: 'write'
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
platforms:
57+
- platform: linux/amd64
58+
runner: ubuntu-24.04
59+
- platform: linux/arm64
60+
runner: ubuntu-24.04-arm
61+
runs-on: ${{ matrix.platforms.runner }}
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v4
65+
with:
66+
fetch-depth: 0
67+
- name: Prepare
68+
run: |
69+
platform=${{ matrix.platforms.platform }}
70+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
71+
- name: Docker meta
72+
id: meta
73+
uses: docker/metadata-action@v5
74+
with:
75+
images: ${{ env.REGISTRY_IMAGE }}
76+
- name: Set up QEMU
77+
uses: docker/setup-qemu-action@v3
78+
- name: Set up Docker Buildx
79+
uses: docker/setup-buildx-action@v3
80+
- name: Login to Docker Hub
81+
uses: docker/login-action@v3
82+
with:
83+
username: mjgpluralsh
84+
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
85+
- name: Build and push by digest
86+
id: build
87+
uses: docker/build-push-action@v6
88+
with:
89+
context: "."
90+
file: "./Dockerfile"
91+
tags: ${{ env.REGISTRY_IMAGE }}
92+
labels: ${{ steps.meta.outputs.labels }}
93+
platforms: ${{ matrix.platforms.platform }}
94+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
95+
cache-from: type=gha
96+
cache-to: type=gha,mode=max
97+
build-args: |
98+
GIT_COMMIT=${{ github.sha }}
99+
- name: Export digest
100+
run: |
101+
mkdir -p ${{ runner.temp }}/digests
102+
digest="${{ steps.build.outputs.digest }}"
103+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
104+
- name: Upload digest
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: digests-${{ env.PLATFORM_PAIR }}
108+
path: ${{ runner.temp }}/digests/*
109+
if-no-files-found: error
110+
retention-days: 1
111+
publish-image:
112+
name: Publish image
113+
needs: [build-image]
114+
runs-on: ubuntu-latest
115+
steps:
116+
- name: Download digests
117+
uses: actions/download-artifact@v4
118+
with:
119+
path: ${{ runner.temp }}/digests
120+
pattern: digests-*
121+
merge-multiple: true
122+
- name: Login to GHCR
123+
uses: docker/login-action@v3
124+
with:
125+
registry: ghcr.io
126+
username: ${{ github.repository_owner }}
127+
password: ${{ secrets.GITHUB_TOKEN }}
128+
- name: Set up Docker Buildx
129+
uses: docker/setup-buildx-action@v3
130+
- name: Docker meta
131+
id: meta
132+
uses: docker/metadata-action@v5
133+
with:
134+
images: |
135+
ghcr.io/pluralsh/pr-governance-webhook
136+
tags: |
137+
type=sha
138+
type=ref,event=pr
139+
type=ref,event=branch
140+
type=semver,pattern={{version}},value=${{ needs.prepare.outputs.new_release_version }}
141+
- name: Create manifest list and push
142+
working-directory: ${{ runner.temp }}/digests
143+
run: |
144+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
145+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)

.github/workflows/publish.yaml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
env:
9+
GOPATH: /home/runner/go/
10+
GOPROXY: "https://proxy.golang.org"
11+
REGISTRY_IMAGE: pluralsh/pluralsh/pr-governance-webhook
12+
jobs:
13+
test:
14+
name: Unit test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
check-latest: true
22+
- run: PATH=$PATH:$GOPATH/bin make test
23+
build-image:
24+
name: Build image
25+
needs: [test]
26+
permissions:
27+
contents: 'read'
28+
id-token: 'write'
29+
packages: 'write'
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
platforms:
34+
- platform: linux/amd64
35+
runner: ubuntu-24.04
36+
- platform: linux/arm64
37+
runner: ubuntu-24.04-arm
38+
runs-on: ${{ matrix.platforms.runner }}
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 0
44+
- name: Prepare
45+
run: |
46+
platform=${{ matrix.platforms.platform }}
47+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
48+
- name: Docker meta
49+
id: meta
50+
uses: docker/metadata-action@v5
51+
with:
52+
images: ${{ env.REGISTRY_IMAGE }}
53+
- name: Set up QEMU
54+
uses: docker/setup-qemu-action@v3
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v3
57+
- name: Login to GHCR
58+
uses: docker/login-action@v3
59+
with:
60+
registry: ghcr.io
61+
username: ${{ github.repository_owner }}
62+
password: ${{ secrets.GITHUB_TOKEN }}
63+
- name: Build and push by digest
64+
id: build
65+
uses: docker/build-push-action@v6
66+
with:
67+
context: "."
68+
file: "./Dockerfile"
69+
tags: ${{ env.REGISTRY_IMAGE }}
70+
labels: ${{ steps.meta.outputs.labels }}
71+
platforms: ${{ matrix.platforms.platform }}
72+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
73+
cache-from: type=gha
74+
cache-to: type=gha,mode=max
75+
build-args: |
76+
GIT_COMMIT=${{ github.sha }}
77+
- name: Export digest
78+
run: |
79+
mkdir -p ${{ runner.temp }}/digests
80+
digest="${{ steps.build.outputs.digest }}"
81+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
82+
- name: Upload digest
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: digests-${{ env.PLATFORM_PAIR }}
86+
path: ${{ runner.temp }}/digests/*
87+
if-no-files-found: error
88+
retention-days: 1
89+
publish-image:
90+
name: Publish image
91+
needs: [build-image]
92+
runs-on: ubuntu-latest
93+
steps:
94+
- name: Download digests
95+
uses: actions/download-artifact@v4
96+
with:
97+
path: ${{ runner.temp }}/digests
98+
pattern: digests-*
99+
merge-multiple: true
100+
- name: Login to GHCR
101+
uses: docker/login-action@v3
102+
with:
103+
registry: ghcr.io
104+
username: ${{ github.repository_owner }}
105+
password: ${{ secrets.GITHUB_TOKEN }}
106+
- name: Set up Docker Buildx
107+
uses: docker/setup-buildx-action@v3
108+
- name: Docker meta
109+
id: meta
110+
uses: docker/metadata-action@v5
111+
with:
112+
images: |
113+
ghcr.io/pluralsh/pr-governance-webhook
114+
tags: type=semver,pattern={{version}}
115+
- name: Create manifest list and push
116+
working-directory: ${{ runner.temp }}/digests
117+
run: |
118+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
119+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
120+

0 commit comments

Comments
 (0)