Skip to content

Commit 89c1b02

Browse files
committed
ci: add actions, docker, signing, more
Signed-off-by: Carlos Alexandro Becker <[email protected]>
1 parent 89061d9 commit 89c1b02

File tree

8 files changed

+228
-34
lines changed

8 files changed

+228
-34
lines changed

.github/dependabot.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: 2
2+
updates:
3+
# Waiting on https://github.com/dependabot/dependabot-core/issues/8166
4+
# - package-ecosystem: zig
5+
# directory: "/"
6+
# schedule:
7+
# interval: "daily"
8+
# time: "08:00"
9+
# labels:
10+
# - "dependencies"
11+
# commit-message:
12+
# prefix: "chore"
13+
# include: "scope"
14+
- package-ecosystem: "github-actions"
15+
directory: "/"
16+
schedule:
17+
interval: "daily"
18+
time: "08:00"
19+
labels:
20+
- "dependencies"
21+
commit-message:
22+
prefix: "chore"
23+
include: "scope"
24+
- package-ecosystem: "docker"
25+
directory: "/"
26+
schedule:
27+
interval: "daily"
28+
time: "08:00"
29+
labels:
30+
- "dependencies"
31+
commit-message:
32+
prefix: "chore"
33+
include: "scope"

.github/workflows/build.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- run: cargo build --verbose
17+
- run: cargo test --verbose
18+
dependabot:
19+
needs: [build]
20+
runs-on: ubuntu-latest
21+
permissions:
22+
pull-requests: write
23+
contents: write
24+
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}}
25+
steps:
26+
- id: metadata
27+
uses: dependabot/fetch-metadata@v2
28+
with:
29+
github-token: "${{ secrets.GITHUB_TOKEN }}"
30+
- run: |
31+
gh pr review --approve "$PR_URL"
32+
gh pr merge --squash --auto "$PR_URL"
33+
env:
34+
PR_URL: ${{github.event.pull_request.html_url}}
35+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/release.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# .github/workflows/release.yml
2+
name: goreleaser
3+
4+
on:
5+
push:
6+
# run only against tags
7+
tags:
8+
- "*"
9+
10+
permissions:
11+
contents: write
12+
packages: write
13+
issues: write
14+
id-token: write
15+
16+
jobs:
17+
goreleaser:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
# More assembly might be required: Docker logins, GPG, etc.
24+
# It all depends on your needs.
25+
- uses: mlugg/setup-zig@v1
26+
- uses: sigstore/[email protected]
27+
- uses: anchore/sbom-action/[email protected]
28+
- uses: docker/setup-qemu-action@v3
29+
- uses: docker/setup-buildx-action@v3
30+
- uses: docker/login-action@v3
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.repository_owner }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
- uses: goreleaser/goreleaser-action@v6
36+
with:
37+
# either 'goreleaser' (default) or 'goreleaser-pro'
38+
distribution: goreleaser
39+
# 'latest', 'nightly', or a semver
40+
version: "~> v2"
41+
args: release --clean
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
45+
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
1+
# Added by goreleaser init:
22
dist/
3-
zig-out
4-
dist/
5-
.zig-cache
3+
.intentionally-empty-file.o
4+
zig-out/
5+
.zig-cache/

.goreleaser.yaml

Lines changed: 105 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,131 @@
88

99
version: 2
1010

11-
project_name: example-zig
11+
project_name: example
1212

13+
# Actually builds the binaries.
1314
builds:
1415
- builder: zig
16+
flags:
17+
- -Doptimize=ReleaseSafe
18+
targets:
19+
- x86_64-linux
20+
- x86_64-windows
21+
- aarch64-linux
22+
- x86_64-macos
23+
- aarch64-macos
1524

16-
universal_binaries:
17-
- replace: true
18-
19-
nfpms:
20-
- formats:
21-
- deb
22-
- rpm
23-
- apk
24-
maintainer: "carlos becker <[email protected]>"
25-
26-
brews:
27-
- name: foo
28-
repository:
29-
name: foo
30-
owner: bar
31-
32-
winget:
33-
- publisher: "Becker Software"
34-
repository:
35-
name: winget
36-
owner: microsoft
37-
short_description: Example Zig software
38-
license: MIT
39-
25+
# Creates archives for each target.
4026
archives:
4127
- format: tar.gz
4228
# this name template makes the OS and Arch compatible with the results of `uname`.
4329
name_template: >-
4430
{{ .ProjectName }}_
45-
{{- .Os }}_
31+
{{- title .Os }}_
4632
{{- if eq .Arch "amd64" }}x86_64
4733
{{- else if eq .Arch "386" }}i386
4834
{{- else }}{{ .Arch }}{{ end }}
49-
{{- if .Arm }}v{{ .Arm }}{{ end }}
5035
# use zip for windows archives
5136
format_overrides:
5237
- goos: windows
5338
format: zip
5439

40+
# Changelog configuration (will be in the github release).
5541
changelog:
5642
sort: asc
5743
filters:
5844
exclude:
5945
- "^docs:"
6046
- "^test:"
47+
48+
# A footer to add to all releases.
49+
release:
50+
footer: >-
51+
52+
---
53+
54+
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).
55+
56+
# Creates Linux packages.
57+
nfpms:
58+
- file_name_template: "{{ .ConventionalFileName }}"
59+
maintainer: Carlos Alexandro Becker <[email protected]>
60+
formats:
61+
- deb
62+
- apk
63+
- rpm
64+
65+
# Creates Darwin universal binaries.
66+
universal_binaries:
67+
- replace: true
68+
69+
# Enables source archives.
70+
source:
71+
enabled: true
72+
73+
# SBOMs for the archives and source archives.
74+
sboms:
75+
- artifacts: archive
76+
- id: source
77+
artifacts: source
78+
79+
# Sign binaries with cosign.
80+
signs:
81+
- cmd: cosign
82+
env:
83+
- COSIGN_EXPERIMENTAL=1
84+
certificate: "${artifact}.pem"
85+
args:
86+
- sign-blob
87+
- "--output-certificate=${certificate}"
88+
- "--output-signature=${signature}"
89+
- "${artifact}"
90+
- "--yes"
91+
artifacts: checksum
92+
output: true
93+
94+
# Create Docker images.
95+
# We create a manifest below, so here the images need the suffix with the
96+
# architecture.
97+
dockers:
98+
- image_templates:
99+
- "ghcr.io/goreleaser/example-zig:{{ .Tag }}-arm64"
100+
dockerfile: Dockerfile
101+
goarch: arm64
102+
build_flag_templates:
103+
- "--pull"
104+
- "--label=org.opencontainers.image.created={{.Date}}"
105+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
106+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
107+
- "--label=org.opencontainers.image.version={{.Version}}"
108+
- "--label=org.opencontainers.image.source={{.GitURL}}"
109+
- image_templates:
110+
- "ghcr.io/goreleaser/example-zig:{{ .Tag }}-amd64"
111+
dockerfile: Dockerfile
112+
goarch: amd64
113+
build_flag_templates:
114+
- "--pull"
115+
- "--label=org.opencontainers.image.created={{.Date}}"
116+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
117+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
118+
- "--label=org.opencontainers.image.version={{.Version}}"
119+
- "--label=org.opencontainers.image.source={{.GitURL}}"
120+
121+
# Here we join both images into a Docker manifest.
122+
docker_manifests:
123+
- name_template: "ghcr.io/goreleaser/example-zig:{{ .Tag }}"
124+
image_templates:
125+
- "ghcr.io/goreleaser/example-zig:{{ .Tag }}-arm64"
126+
- "ghcr.io/goreleaser/example-zig:{{ .Tag }}-amd64"
127+
128+
# Sign the Docker images with cosign as well.
129+
docker_signs:
130+
- cmd: cosign
131+
env:
132+
- COSIGN_EXPERIMENTAL=1
133+
artifacts: images
134+
output: true
135+
args:
136+
- "sign"
137+
- "${artifact}"
138+
- "--yes"

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM ubuntu
2+
COPY example /usr/bin/example
3+
ENTRYPOINT [ "/usr/bin/example" ]

build.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void {
1616
const optimize = b.standardOptimizeOption(.{});
1717

1818
const lib = b.addStaticLibrary(.{
19-
.name = "example-zig",
19+
.name = "example",
2020
// In this case the main source file is merely a path, however, in more
2121
// complicated build scripts, this could be a generated file.
2222
.root_source_file = b.path("src/root.zig"),
@@ -30,7 +30,7 @@ pub fn build(b: *std.Build) void {
3030
b.installArtifact(lib);
3131

3232
const exe = b.addExecutable(.{
33-
.name = "example-zig",
33+
.name = "example",
3434
.root_source_file = b.path("src/main.zig"),
3535
.target = target,
3636
.optimize = optimize,

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// It is redundant to include "zig" in this name because it is already
88
// within the Zig package namespace.
9-
.name = "example-zig",
9+
.name = "example",
1010

1111
// This is a [Semantic Version](https://semver.org/).
1212
// In a future version of Zig it will be used for package deduplication.

0 commit comments

Comments
 (0)