Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 22 additions & 41 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ on:
tags:
- "v*"

# The list of permissions is explained on the GitHub doc:
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#repository-permissions
permissions:
# Write permission is needed to create a new release.
contents: write
# Allow read access to pull requests. Used by the linter action.
pull-requests: read

jobs:
linter:
name: Linter on a PR
Expand All @@ -25,51 +33,24 @@ jobs:
env:
CODE_PATH: ${{ github.workspace }}

publish:
runs-on: ubuntu-24.04
releases:
needs: [tests]
name: GoReleaser Build on Linux
if: ${{ github.ref_type == 'tag' }}
env:
GOX_ARCHITECTURES: amd64 386
runs-on: ubuntu-24.04
steps:
# Currently there is no possibility to get a tag name. Hence we filter the GITHUB_REF variable which contains something like "refs/tags/v2.0.0" if the tag is "v2.0.0". The value can be used with "steps.tag_name.outputs.TAG_NAME"
- name: Get tag name
id: tag_name
run: |
TAG_NAME="${GITHUB_REF#refs/tags/}"
echo "TAG_NAME=${TAG_NAME}" >> "$GITHUB_OUTPUT"
echo "$TAG_NAME"

- name: Checkout the code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup Go environment
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # required by GoReleaser (https://goreleaser.com/ci/actions/#fetch-all-history)
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: "go.mod"
check-latest: true
- run: go version

- name: Build the binaries
env:
TAG_NAME: ${{ steps.tag_name.outputs.TAG_NAME }}
run: |
go install github.com/mitchellh/gox@latest
CGO_ENABLED=0 gox -os="linux" -arch="$GOX_ARCHITECTURES" -output="dist/link-${TAG_NAME}-{{.OS}}-{{.Arch}}/{{.Dir}}" -ldflags="-X main.Version=${TAG_NAME}" . ./cmd/...

- name: Archive the built binaries
env:
TAG_NAME: ${{ steps.tag_name.outputs.TAG_NAME }}
run: |
for gox_archi in $GOX_ARCHITECTURES; do
echo "Archive release targetted to $gox_archi"
# Gox compiles link-client and an executable named "v3" instead of "link"..
mv "dist/link-${TAG_NAME}-linux-${gox_archi}/v3" "dist/link-${TAG_NAME}-linux-${gox_archi}/link"
tar --directory=dist -czvf "dist/link-${TAG_NAME}-linux-${gox_archi}.tar.gz" "link-${TAG_NAME}-linux-${gox_archi}"
done

- name: Release the new version
uses: softprops/action-gh-release@v3
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3
with:
generate_release_notes: true
files: dist/*.tar.gz
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CGO_ENABLED: 0
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
/link-client
generate-mock
cmd/link-client/link-client
/dist/link*
# dist contains the archives created by GoReleaser
dist
.vscode
46 changes: 46 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: 2

before:
hooks:
- go mod tidy

builds:
- id: link
binary: link
main: .
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- 386
ldflags: -X main.Version={{ .Tag }}

- id: link-client
binary: link-client
main: ./cmd/link-client
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- 386
ldflags: -X main.Version={{ .Tag }}

archives:
- formats: ["tar.gz"]
name_template: "{{ .ProjectName }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}"
wrap_in_directory: true

checksum:
name_template: checksums.txt

changelog:
sort: asc
use: github-native
filters:
exclude:
- "^docs:"
- "^test:"
Empty file removed dist/.gitkeep
Empty file.