Skip to content

Commit

Permalink
ci: add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
luissimas committed Jun 21, 2024
1 parent 8ddf597 commit 00aa62b
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [main]
pull_request:
branches: [main]
workflow_call:

permissions:
contents: read
Expand Down Expand Up @@ -66,7 +67,7 @@ jobs:
with:
go-version-file: 'go.mod'
- name: Build
run: go build -o /dev/null ./cmd/zettelkasten-exporter/main.go
run: go build -o /dev/null
test:
needs: build
runs-on: ubuntu-latest
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release

on:
push:
tags:
- "v*.*.*"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
check:
uses: ./.github/workflows/check.yaml
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the container registry
uses: docker/login-action@v5
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
- name: Run goreleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bin
dist/
46 changes: 46 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 2

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -o /zettelkasten-exporter ./cmd/zettelkasten-exporter/main.go
RUN CGO_ENABLED=0 GOOS=linux go build -o /zettelkasten-exporter

FROM gcr.io/distroless/base-debian12 AS release-stage

Expand Down
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
BINARY_NAME=zettelkasten-exporter

.PHONY: all clean format vet lint test get build run
.PHONY: all clean format vet lint test build run

all: format vet test build
all: format vet build test

clean:
go clean
Expand All @@ -20,11 +20,8 @@ lint:
test:
go test ./...

get:
go get ./...

build: get
go build -o bin/$(BINARY_NAME) ./cmd/zettelkasten-exporter/main.go
build:
go build -o bin/$(BINARY_NAME)

run: build
LOG_LEVEL=INFO \
Expand Down
File renamed without changes.

0 comments on commit 00aa62b

Please sign in to comment.