Skip to content

Commit 8388612

Browse files
authored
ci: rewrite GitHub action workflows (#346)
* add permission blocks * removing actions/cache steps * add annotations to build step * reordering parts in workflow * add sbom and cosign * update readme badges
1 parent 3b25014 commit 8388612

File tree

5 files changed

+59
-28
lines changed

5 files changed

+59
-28
lines changed

.github/workflows/build.yml

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ on:
1313
- "go.sum"
1414
release:
1515
types: [published]
16+
workflow_dispatch:
17+
18+
permissions:
19+
contents: read
20+
id-token: write
21+
packages: write
1622

1723
jobs:
1824
build:
@@ -21,21 +27,6 @@ jobs:
2127
- name: Checkout
2228
uses: actions/checkout@v4
2329

24-
- name: Login to DockerHub
25-
if: github.event_name != 'pull_request'
26-
uses: docker/login-action@v3
27-
with:
28-
username: ${{ secrets.DOCKERHUB_USERNAME }}
29-
password: ${{ secrets.DOCKERHUB_TOKEN }}
30-
31-
- name: Login to GitHub Container Registry
32-
if: github.event_name != 'pull_request'
33-
uses: docker/login-action@v3
34-
with:
35-
registry: ghcr.io
36-
username: ${{ github.actor }}
37-
password: ${{ secrets.GITHUB_TOKEN }}
38-
3930
- name: Docker meta
4031
id: docker_meta
4132
uses: docker/metadata-action@v5
@@ -49,40 +40,70 @@ jobs:
4940
type=semver,pattern={{version}}
5041
type=semver,pattern={{major}}
5142
type=semver,pattern={{major}}.{{minor}}
43+
env:
44+
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
45+
46+
- name: Install Cosign
47+
if: github.event_name != 'pull_request'
48+
uses: sigstore/cosign-installer@v3
5249

5350
- name: Set up QEMU
5451
uses: docker/setup-qemu-action@v3
5552

5653
- name: Set up Docker Buildx
5754
uses: docker/setup-buildx-action@v3
5855

59-
- name: Go Build Cache for Docker layers
60-
uses: actions/cache@v4
56+
- name: Login to DockerHub
57+
if: github.event_name != 'pull_request'
58+
uses: docker/login-action@v3
6159
with:
62-
path: go-build-cache
63-
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}
60+
username: ${{ secrets.DOCKERHUB_USERNAME }}
61+
password: ${{ secrets.DOCKERHUB_TOKEN }}
6462

65-
- name: Inject go-build-cache into docker
66-
uses: reproducible-containers/buildkit-cache-dance@v2.1.4
63+
- name: Login to GitHub Container Registry
64+
if: github.event_name != 'pull_request'
65+
uses: docker/login-action@v3
6766
with:
68-
cache-source: go-build-cache
67+
registry: ghcr.io
68+
username: ${{ github.actor }}
69+
password: ${{ secrets.GITHUB_TOKEN }}
6970

7071
- name: Build and push
72+
id: docker_build
7173
uses: docker/build-push-action@v5
7274
with:
7375
context: .
74-
file: ./Dockerfile
7576
platforms: linux/amd64,linux/arm/v7,linux/arm64
7677
push: ${{ github.event_name != 'pull_request' }}
77-
tags: ${{ steps.docker_meta.outputs.tags }}
78+
annotations: ${{ steps.docker_meta.outputs.annotations }}
7879
labels: ${{ steps.docker_meta.outputs.labels }}
80+
tags: ${{ steps.docker_meta.outputs.tags }}
7981
cache-from: type=gha
8082
cache-to: type=gha,mode=max
83+
sbom: true
8184
build-args: |
8285
TibiaDataBuildBuilder=github
8386
TibiaDataBuildRelease=${{ fromJSON(steps.docker_meta.outputs.json).labels['org.opencontainers.image.version'] }}
8487
TibiaDataBuildCommit=${{ fromJSON(steps.docker_meta.outputs.json).labels['org.opencontainers.image.revision'] }}
8588
89+
- name: Sign the images (with GitHub OIDC Token)
90+
if: github.event_name != 'pull_request'
91+
run: |
92+
cosign sign --yes --recursive \
93+
tibiadata/tibiadata-api-go@${{ steps.docker_build.outputs.digest }}
94+
95+
cosign sign --yes --recursive \
96+
ghcr.io/tibiadata/tibiadata-api-go@${{ steps.docker_build.outputs.digest }}
97+
98+
dockerhub:
99+
if: github.event_name == 'release'
100+
runs-on: ubuntu-latest
101+
needs:
102+
- build
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@v4
106+
86107
- name: Docker Hub Description
87108
uses: peter-evans/dockerhub-description@v4
88109
if: github.event_name == 'release'

.github/workflows/codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
push:
55
pull_request:
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
codecov:
912
runs-on: ubuntu-latest

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
schedule:
99
- cron: "44 15 * * 0"
1010

11+
permissions:
12+
contents: read
13+
security-events: write
14+
1115
jobs:
1216
analyze:
1317
name: Analyze

.github/workflows/documentation.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
release:
55
types: [published]
66

7+
permissions:
8+
contents: write
9+
710
jobs:
811
documentation:
912
runs-on: ubuntu-latest

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# TibiaData API in Golang
22

3-
[![GitHub CI](https://github.com/TibiaData/tibiadata-api-go/workflows/build/badge.svg?branch=main)](https://github.com/TibiaData/tibiadata-api-go/actions?query=workflow%3Abuild)
3+
[![GitHub CI](https://img.shields.io/github/actions/workflow/status/tibiadata/tibiadata-api-go/build.yml?branch=main&logo=github)](https://github.com/tibiadata/tibiadata-api-go/actions/workflows/build.yml)
44
[![Codecov](https://codecov.io/gh/TibiaData/tibiadata-api-go/branch/main/graph/badge.svg?token=PSBNLBI10C)](https://codecov.io/gh/TibiaData/tibiadata-api-go)
5-
[![GitHub go.mod version](https://img.shields.io/github/go-mod/go-version/tibiadata/tibiadata-api-go)](https://github.com/tibiadata/tibiadata-api-go/blob/main/go.mod)
6-
[![Docker version](https://img.shields.io/docker/v/tibiadata/tibiadata-api-go/latest)](https://hub.docker.com/r/tibiadata/tibiadata-api-go)
7-
[![Docker size](https://img.shields.io/docker/image-size/tibiadata/tibiadata-api-go/latest)](https://hub.docker.com/r/tibiadata/tibiadata-api-go)
5+
[![GitHub go.mod version](https://img.shields.io/github/go-mod/go-version/tibiadata/tibiadata-api-go?logo=go)](https://github.com/tibiadata/tibiadata-api-go/blob/main/go.mod)
6+
[![GitHub release](https://img.shields.io/github/v/release/tibiadata/tibiadata-api-go?sort=semver&logo=github)](https://github.com/tibiadata/tibiadata-api-go/releases)
7+
[![Docker image size (tag)](https://img.shields.io/docker/image-size/tibiadata/tibiadata-api-go/latest?logo=docker)](https://hub.docker.com/r/tibiadata/tibiadata-api-go)
88
[![GitHub license](https://img.shields.io/github/license/tibiadata/tibiadata-api-go)](https://github.com/tibiadata/tibiadata-api-go/blob/main/LICENSE)
99

1010
TibiaData API written in Golang and deployed in container (version v3 and above).

0 commit comments

Comments
 (0)