Skip to content

Commit 5891842

Browse files
authored
Merge pull request #115 from tmccombs/goreleaser
chore: Use goreleaser to publish releases
2 parents d7663d6 + adead17 commit 5891842

File tree

4 files changed

+78
-79
lines changed

4 files changed

+78
-79
lines changed

.github/workflows/deploy.yml

+13-66
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,31 @@
11
name: Deploy
22

33
on:
4-
release:
5-
types: [created]
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
permissions:
9+
contents: write
610

711
jobs:
812
deploy:
913
name: Deploy
1014
runs-on: ubuntu-latest
11-
strategy:
12-
matrix:
13-
os:
14-
- name: linux
15-
ext: ''
16-
- name: darwin
17-
ext: ''
18-
- name: windows
19-
ext: '.exe'
20-
arch:
21-
- "386"
22-
- amd64
23-
- arm64
24-
include:
25-
- os:
26-
name: darwin
27-
ext: ''
28-
arch: "arm64"
29-
exclude:
30-
- os:
31-
name: darwin
32-
ext: ''
33-
arch: "386"
34-
fail-fast: false
35-
env:
36-
GOOS: ${{ matrix.os.name }}
37-
GOARCH: ${{ matrix.arch }}
3815
steps:
3916
- uses: actions/checkout@v4
4017
- uses: actions/setup-go@v5
4118
with:
42-
go-version: '~1.22.5'
43-
- name: Update environment
44-
run: |
45-
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
46-
echo "TARGET_NAME=hcl2json_${{ matrix.os.name }}_${{ matrix.arch}}${{ matrix.os.ext }}" >> $GITHUB_ENV
47-
- name: Build
48-
run: 'go build -ldflags="-X main.Version=${{ env.VERSION }}"'
49-
- name: Upload
50-
env:
51-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52-
run: |
53-
mv hcl2json${{ matrix.os.ext }} $TARGET_NAME
54-
gh release upload v$VERSION $TARGET_NAME
55-
56-
deploy_docker:
57-
name: Push to docker
58-
runs-on: ubuntu-latest
59-
steps:
60-
- uses: actions/checkout@v4
19+
go-version: '~1.24.1'
6120
- name: login to docker
6221
uses: docker/login-action@v3
6322
with:
6423
username: ${{ secrets.DOCKER_HUB_USERNAME }}
6524
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
66-
- name: Set up docker buildx
67-
uses: docker/setup-buildx-action@v3
68-
- name: Docker meta
69-
id: docker_meta
70-
uses: docker/metadata-action@v5
71-
with:
72-
images: ${{ secrets.DOCKER_HUB_USERNAME }}/hcl2json
73-
tags: |
74-
type=semver,pattern={{version}}
75-
type=semver,pattern={{major}}.{{minor}}
76-
- name: Build and push docker to dockerhub
77-
uses: docker/build-push-action@v6
25+
- name: Release
26+
uses: goreleaser/goreleaser-action@v2
7827
with:
79-
context: .
80-
file: ./Dockerfile
81-
platforms: linux/amd64,linux/arm64
82-
push: true
83-
tags: ${{ steps.docker_meta.outputs.tags }}
84-
labels: ${{ steps.docker_meta.outputs.labels }}
28+
version: latest
29+
args: release --clean
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ hcl2json
1717

1818
# Golang vendor files
1919
vendor/
20+
# Added by goreleaser init:
21+
dist/

.goreleaser.yaml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
3+
4+
version: 2
5+
6+
before:
7+
hooks:
8+
# You may remove this if you don't use go modules.
9+
- go mod tidy
10+
11+
builds:
12+
- env:
13+
- CGO_ENABLED=0
14+
goos:
15+
- linux
16+
- windows
17+
- darwin
18+
19+
archives:
20+
- formats: [ 'tar.gz' ]
21+
# this name template makes the OS and Arch compatible with the results of `uname`.
22+
name_template: >-
23+
{{ .ProjectName }}_
24+
{{- title .Os }}_
25+
{{- if eq .Arch "amd64" }}x86_64
26+
{{- else if eq .Arch "386" }}i386
27+
{{- else }}{{ .Arch }}{{ end }}
28+
{{- if .Arm }}v{{ .Arm }}{{ end }}
29+
# use zip for windows archives
30+
format_overrides:
31+
- goos: windows
32+
formats: [ 'zip' ]
33+
34+
dockers:
35+
- image_templates:
36+
- "tmccombs/{{ .ProjectName }}:latest"
37+
- "tmccombs/{{ .ProjectName }}:{{ .Version }}"
38+
- "tmccombs/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}"
39+
build_flag_templates:
40+
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
41+
- "--label=org.opencontainers.image.description=Convert HCL to JSON"
42+
- "--label=org.opencontainers.image.url=https://github.com/tmccombs/hcl2json"
43+
- "--label=org.opencontainers.image.source=https://github.com/tmccombs/hcl2json"
44+
- "--label=org.opencontainers.image.version={{ .Version }}"
45+
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
46+
- "--label=org.opencontainers.image.created={{ .Date }}"
47+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
48+
49+
50+
changelog:
51+
sort: asc
52+
filters:
53+
exclude:
54+
- "^docs:"
55+
- "^test:"
56+
57+
release:
58+
footer: >-
59+
60+
---
61+
62+
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).

Dockerfile

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
FROM golang as build
2-
WORKDIR /go/src/app
3-
COPY go.sum .
4-
COPY go.mod .
5-
COPY main.go .
6-
COPY convert/ ./convert/
7-
WORKDIR /go/src/app
8-
ENV GOPATH= CGO_ENABLED=0
9-
RUN go get .
10-
RUN go build -a -ldflags '-s' -o /hcl2json .
11-
12-
##################
131
FROM scratch
142
LABEL maintainer="Thayne McCombs <https://github.com/tmccombs>"
15-
COPY --from=build /hcl2json /hcl2json
3+
COPY hcl2json /hcl2json
164
ENTRYPOINT [ "/hcl2json" ]

0 commit comments

Comments
 (0)