Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(publish): compile Windows release on Windows #806

Merged
merged 3 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 30 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Test and Release Go CLI

on:
push:
on: [push]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a way to write the same things with a different syntax, and I prefer this one.


jobs:
tests:
Expand All @@ -13,13 +12,13 @@ jobs:
with:
go-version-file: "go.mod"
check-latest: true
- run: go version
cache: true
- name: Execute the tests
run: go test -race ./...

release:
releases:
needs: tests
name: GoReleaser Build
name: GoReleaser Build on All OS but Windows
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
Expand All @@ -30,11 +29,36 @@ jobs:
with:
go-version-file: "go.mod"
check-latest: true
- run: go version
cache: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

releases-windows:
needs: tests
name: GoReleaser Build on Windows
if: startsWith(github.ref, 'refs/tags/')
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/
- uses: actions/setup-go@v3
with:
go-version-file: "go.mod"
check-latest: true
cache: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, what is the use of this cache property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/actions/setup-go#caching-dependency-files-and-build-outputs

The action has a built-in functionality for caching and restoring go modules and build outputs.

It should speed up a bit the CI execution.

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --config .goreleaser-windows.yaml --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: List files in the repository
run: |
ls ${{ github.workspace }}/dist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this debug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups, yes

34 changes: 34 additions & 0 deletions .goreleaser-windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# We need a specific GoRelease file for Windows because we don't want to use Go cross compile feature. We prefer compiling on an actual Windows.
before:
hooks:
- go mod tidy
builds:
- id: scalingo
binary: scalingo
main: ./scalingo
goos:
- windows
goarch:
- amd64
- arm64
- 386

# Custom ldflags templates.
# https://goreleaser.com/customization/templates/
ldflags: -X main.buildstamp={{.Date}}
-X main.githash={{.FullCommit}}

archives:
- name_template: 'scalingo_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
checksum:
name_template: "checksums_windows.txt"
changelog:
use: github-native
filters:
exclude:
- "^docs:"
- "^test:"