ci: split between tags and normal branches

This commit is contained in:
Marvin Preuss 2024-03-20 09:14:46 +00:00
parent 6e66ab6084
commit d5883b8419
4 changed files with 92 additions and 5 deletions

16
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,16 @@
name: Earthly snapshot
on:
push:
tags:
- "*"
jobs:
build:
runs-on: ubuntu-latest
env:
FORCE_COLOR: 1
steps:
- uses: actions/checkout@v4
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.8.6/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Run earthly
run: earthly --ci --push +ci --SNAPSHOT=false --GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}

View File

@ -1,9 +1,11 @@
name: Earthly +build
name: Earthly snapshot
on:
push:
branches: [main]
branches:
- '*'
pull_request:
branches: [main]
branches:
- '*'
jobs:
build:
runs-on: ubuntu-latest
@ -13,5 +15,5 @@ jobs:
- uses: actions/checkout@v4
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.8.6/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Run build
run: earthly --ci --push +ci
- name: Run earthly
run: earthly --ci +ci --SNAPSHOT=true

41
.goreleaser.yml Normal file
View File

@ -0,0 +1,41 @@
project_name: "glucose_exporter"
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
ldflags:
- "-s"
- "-w"
- "-extldflags '-static'"
- "-X git.wobcom.de/smartmetering/kerouac/cmd.version={{.Version}}"
- "-X git.wobcom.de/smartmetering/kerouac/cmd.commit={{.ShortCommit}}"
- "-X git.wobcom.de/smartmetering/kerouac/cmd.date={{.Date}}"
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{.Tag}}-next"
source:
format: tar.gz
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test"
- "^ci"
- "^lint"
- "^build"
- "happy linting"
- "^chore"
- "^style"
- "^Revert"
release:
github:
owner: xsteadfastx
name: glucose_exporter
footer: |-
## docker
`docker pull ghcr.io/xsteadfastx/glucose_exporter:{{ trimprefix .Tag "v"}}`

View File

@ -22,8 +22,14 @@ code:
SAVE ARTIFACT . code
ci:
FROM +deps
ARG SNAPSHOT=true
ARG GITHUB_TOKEN
BUILD +test
BUILD +lint
COPY (+goreleaser/dist/metadata.json --SNAPSHOT=$SNAPSHOT --GITHUB_TOKEN=$GITHUB_TOKEN) /tmp/metadata.json
ARG DOCKER_TAG=$(cat /tmp/metadata.json|jq -r .version)
BUILD +docker --DOCKER_TAG=$DOCKER_TAG
test:
COPY +code/code ./
@ -42,9 +48,31 @@ deps:
FROM +base
RUN (cd /tmp; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$GOLANGCILINT_VERSION)
RUN (cd /tmp; go install github.com/goreleaser/goreleaser@$GORELEASER_VERSION)
RUN apk add --no-cache \
git \
jq
lint:
FROM +deps
COPY +code/code ./
COPY .golangci.yml .golangci.yml
RUN golangci-lint run
goreleaser:
FROM +deps
ARG SNAPSHOT=true
ARG GITHUB_TOKEN
IF [ "$SNAPSHOT" = "true" ]
ARG CMD="release --snapshot --clean"
ELSE
ARG CMD="release --clean"
END
COPY . .
RUN goreleaser $CMD
SAVE ARTIFACT dist dist
docker:
FROM scratch
ARG DOCKER_TAG
COPY +goreleaser/dist/glucose_exporter_linux_amd64_v1/glucose_exporter /bin/glucose_exporter
SAVE IMAGE --push ghcr.io/xsteadfastx/glucose_exporter:$DOCKER_TAG