From d5883b841939cc6f70fcc079e2ad37a3edcea027 Mon Sep 17 00:00:00 2001 From: Marvin Preuss Date: Wed, 20 Mar 2024 09:14:46 +0000 Subject: [PATCH] ci: split between tags and normal branches --- .github/workflows/release.yml | 16 +++++++++ .github/workflows/{ci.yml => snapshot.yml} | 12 ++++--- .goreleaser.yml | 41 ++++++++++++++++++++++ Earthfile | 28 +++++++++++++++ 4 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml rename .github/workflows/{ci.yml => snapshot.yml} (71%) create mode 100644 .goreleaser.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d451627 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/.github/workflows/ci.yml b/.github/workflows/snapshot.yml similarity index 71% rename from .github/workflows/ci.yml rename to .github/workflows/snapshot.yml index f507614..873702d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/snapshot.yml @@ -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 diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..04704e7 --- /dev/null +++ b/.goreleaser.yml @@ -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"}}` diff --git a/Earthfile b/Earthfile index 34a02fd..2dd83d8 100644 --- a/Earthfile +++ b/Earthfile @@ -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