Skip to content

Commit

Permalink
feat: Re-enable building with Go 1.16
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Oct 3, 2021
1 parent 34f8dae commit 134d775
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 18 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ jobs:
sudo install -m 755 age/age-keygen /usr/local/bin
- name: Test
run: go test -race ./...
test-openbsd:
runs-on: macos-latest
env:
VAGRANT_BOX: openbsd6
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache Vagrant Boxes
uses: actions/cache@v2
with:
path: ~/.vagrant.d
key: ${{ runner.os }}-vagrant-${{ env.VAGRANT_BOX }}-${{ hashFiles('assets/vagrant/*.Vagrantfile') }}
restore-keys: |
${{ runner.os }}-vagrant-${{ env.VAGRANT_BOX }}-
- name: Test
run: |
( cd assets/vagrant && ./test.sh openbsd6 )
test-ubuntu:
runs-on: ubuntu-18.04
steps:
Expand Down Expand Up @@ -167,6 +184,36 @@ jobs:
with:
name: chezmoi-windows-amd64.exe
path: dist/chezmoi-nocgo_windows_amd64/chezmoi.exe
test-ubuntu-go1-16:
runs-on: ubuntu-18.04
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: Checkout
uses: actions/checkout@v2
- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-ubuntu-go-1-16-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-ubuntu-go-1-16-
- name: Build
run: |
go build ./...
- name: Run
run: |
go run . --version
- name: Install age
run: |
cd $(mktemp -d)
curl -fsSL https://dl.filippo.io/age/v${AGE_VERSION}?for=linux/amd64 | tar xzf -
sudo install -m 755 age/age /usr/local/bin
sudo install -m 755 age/age-keygen /usr/local/bin
- name: Test
run: go test ./...
test-windows:
runs-on: windows-latest
steps:
Expand Down Expand Up @@ -275,6 +322,7 @@ jobs:
- test-fedora
- test-freebsd
- test-macos
- test-openbsd6
- test-ubuntu
- test-windows
runs-on: ubuntu-18.04
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test-docker:

.PHONY: test-vagrant
test-vagrant:
( cd assets/vagrant && ./test.sh debian11-i386 freebsd13 )
( cd assets/vagrant && ./test.sh debian11-i386 freebsd13 openbsd6 )

.PHONY: coverage-html
coverage-html: coverage
Expand Down
6 changes: 0 additions & 6 deletions assets/docker/fedora.entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@

set -eufo pipefail

GO_VERSION=$(grep GO_VERSION: /chezmoi/.github/workflows/main.yml | awk '{ print $2 }' )

go get "golang.org/dl/go${GO_VERSION}"
"${HOME}/go/bin/go${GO_VERSION}" download
export PATH="${HOME}/sdk/go${GO_VERSION}/bin:${PATH}"

( cd /chezmoi && go test ./... )
2 changes: 0 additions & 2 deletions assets/vagrant/openbsd6.Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# OpenBSD currently includes Go version 1.16.2, but chezmoi requires version
# 1.17 or later.
Vagrant.configure("2") do |config|
config.vm.box = "generic/openbsd6"
config.vm.define :openbsd6
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ chezmoi's source code.

## Developing locally

chezmoi requires Go 1.17 or later.
chezmoi requires Go 1.16 or later.

chezmoi is a standard Go project, using standard Go tooling, with a few extra
tools. Ensure that these extra tools are installed with:
Expand Down
6 changes: 3 additions & 3 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ lock include `diff`, `status`, and `verify`.

## I'm getting errors trying to build chezmoi from source

chezmoi requires Go version 1.17 or later. You can check the version of Go with:
chezmoi requires Go version 1.16 or later. You can check the version of Go with:

```console
$ go version
Expand All @@ -458,8 +458,8 @@ If you try to build chezmoi with an earlier version of Go you will get the error
package github.com/twpayne/chezmoi/v2: build constraints exclude all Go files in /home/twp/src/github.com/twpayne/chezmoi
```

This is because chezmoi includes the build tag `go1.17` in `main.go`, which is
only set on Go 1.17 or later.
This is because chezmoi includes the build tag `go1.16` in `main.go`, which is
only set on Go 1.16 or later.

For more details on building chezmoi, see the [Contributing
Guide]([CONTRIBUTING.md](https://github.com/twpayne/chezmoi/blob/master/docs/CONTRIBUTING.md)).
Expand Down
2 changes: 1 addition & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ $ cd chezmoi
$ make install
```

Building chezmoi requires Go 1.17 or later.
Building chezmoi requires Go 1.16 or later.

---
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/twpayne/chezmoi/v2

go 1.17
go 1.16

require (
filippo.io/age v1.0.0
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func withTestUser(t *testing.T, username string) configOption {
c.homeDir = filepath.Join("/", "home", username)
env = "HOME"
}
t.Setenv(env, c.homeDir)
testSetenv(t, env, c.homeDir)
var err error
c.homeDirAbsPath, err = chezmoi.NormalizePath(c.homeDir)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions internal/cmd/util_go1.16_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build !go1.17
// +build !go1.17

package cmd

import (
"os"
"testing"
)

func testSetenv(t *testing.T, key, value string) {
t.Helper()
prevValue := os.Getenv(key)
t.Cleanup(func() {
os.Setenv(key, prevValue)
})
os.Setenv(key, value)
}
11 changes: 11 additions & 0 deletions internal/cmd/util_go1.17_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build go1.17
// +build go1.17

package cmd

import "testing"

func testSetenv(t *testing.T, key, value string) {
t.Helper()
t.Setenv(key, value)
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build go1.17
// +build go1.17
//go:build go1.16
// +build go1.16

//go:generate go run . completion bash -o completions/chezmoi-completion.bash
//go:generate go run . completion fish -o completions/chezmoi.fish
Expand Down

0 comments on commit 134d775

Please sign in to comment.