Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit dfb28f1

Browse files
Merge pull request #178 from protocol/next
update to Go 1.17, update all repos with the updated workflows
2 parents 5414f41 + 04813da commit dfb28f1

File tree

7 files changed

+173
-47
lines changed

7 files changed

+173
-47
lines changed

.github/workflows/check-3rd-party.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ status=0
77

88
for line in `sed -ne 's/[[:space:]-]*uses:[[:space:]]*//p' $1 | sed -e 's/\s*#.*$//'`; do
99
author=`echo $line | awk -F/ '{print $1}'`
10-
if [[ $author == "actions" || $author == "protocol" ]]; then continue; fi
10+
# We trust:
11+
# - .: local workflows
12+
# "actions": workflows authored by GitHub
13+
# "protocol": workflows published in the protocol org
14+
if [[ $author == "." || $author == "actions" || $author == "protocol" ]]; then continue; fi
1115
version=`echo $line | awk -F@ '{print $2}' | awk '{print $1}'`
1216
if ! [[ "$version" =~ ^[a-f0-9]{40}$ ]]; then
1317
status=1

.github/workflows/copy-workflow.yml

+73-30
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
# This workflow is triggered by the dispatch workflow.
22

3-
on:
4-
repository_dispatch:
5-
types: [ copy-workflow ]
6-
73
name: Deploy
84

5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
head_commit_url:
9+
description: "github.event.head_commit.url of the dispatcher"
10+
required: true
11+
files:
12+
description: "List of files to deploy"
13+
required: true
14+
targets:
15+
description: "List of repositories to deploy to"
16+
required: true
17+
918
jobs:
1019
copy:
1120
runs-on: ubuntu-latest
1221
strategy:
1322
fail-fast: false
1423
matrix:
15-
cfg: ${{ github.event.client_payload.targets }}
24+
cfg: ${{ fromJson(github.event.inputs.targets) }}
1625
env:
1726
TARGET_REPO_DIR: "target-repo"
1827
TEMPLATE_REPO_DIR: "template-repo"
1928
TEMPLATE_DIR: "templates"
2029
NEEDS_UPDATE: 0
2130
INITIAL_TEST_DEPLOYMENT: 0
31+
GO_VERSION_BUMP: 0
2232
GITHUB_USER: "web3-bot"
2333
GITHUB_EMAIL: "[email protected]"
2434
name: ${{ matrix.cfg.target }}
@@ -38,10 +48,11 @@ jobs:
3848
with:
3949
# This should be the same Go version we use in the go-check workflow.
4050
# go mod tidy, go vet, staticcheck and gofmt might behave differently depending on the version.
41-
go-version: "1.16.x"
51+
stable: 'false'
52+
go-version: "1.17.0-rc1"
4253
- name: git config
54+
working-directory: ${{ env.TARGET_REPO_DIR }}
4355
run: |
44-
cd $TARGET_REPO_DIR
4556
git config user.name ${{ env.GITHUB_USER }}
4657
git config user.email ${{ env.GITHUB_EMAIL }}
4758
- name: is initial test workflow deployment
@@ -50,58 +61,91 @@ jobs:
5061
echo "INITIAL_TEST_DEPLOYMENT=1" >> $GITHUB_ENV
5162
fi
5263
- name: remove the autorebase workflow # TODO: remove this step once all autorebase.yml files have been deleted
64+
working-directory: ${{ env.TARGET_REPO_DIR }}
5365
run: |
54-
cd $TARGET_REPO_DIR
5566
if [[ -f .github/workflows/autorebase.yml ]]; then
5667
git rm .github/workflows/autorebase.yml
5768
git commit -m "remove the autorebase workflow"
5869
fi
5970
- name: remove Travis (on initial deployment)
6071
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 }}
72+
working-directory: ${{ env.TARGET_REPO_DIR }}
6173
run: |
62-
cd $TARGET_REPO_DIR
6374
if [[ -f .travis.yml ]]; then
6475
git rm .travis.yml
6576
git commit -m "disable Travis"
6677
fi
6778
- name: remove CircleCI (on initial deployment)
6879
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 }}
80+
working-directory: ${{ env.TARGET_REPO_DIR }}
6981
run: |
70-
cd $TARGET_REPO_DIR
7182
if [[ -d .circleci ]]; then
7283
git rm -r .circleci
7384
git commit -m "disable CircleCI"
7485
fi
7586
- name: remove gx (on initial deployment)
7687
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 }}
88+
working-directory: ${{ env.TARGET_REPO_DIR }}
7789
run: |
78-
cd $TARGET_REPO_DIR
7990
if [[ -d .gx ]]; then
8091
git rm -r .gx
8192
git commit -m "remove .gx"
8293
fi
83-
- name: go mod tidy (on initial deployment)
84-
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 }}
85-
run: |
86-
cd $TARGET_REPO_DIR
87-
go mod edit -go 1.15
88-
go mod tidy
89-
if ! git diff --quiet; then
90-
git add .
91-
git commit -m "set Go version to 1.15 and run go mod tidy"
92-
fi
93-
- name: gofmt (on initial deployment)
94-
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 }}
94+
- name: bump go.mod go version if needed
95+
uses: protocol/[email protected]
96+
with:
97+
working-directory: ${{ env.TARGET_REPO_DIR }}
98+
run: |
99+
# We want our modules to support two Go versions at a time.
100+
# As of August 2021, Go 1.17 is the latest stable.
101+
# go.mod's Go version declares the language version being used.
102+
# As such, it has to be the minimum of all Go versions supported.
103+
# Bump this every six months, as new Go versions come out.
104+
TARGET_VERSION=1.16
105+
106+
# Note that the "<" comparison doesn't understand semver,
107+
# but it should be good enough for the foreseeable future.
108+
CURRENT_VERSION=$(go list -m -f {{.GoVersion}})
109+
110+
if [[ $CURRENT_VERSION < $TARGET_VERSION ]]; then
111+
echo "GO_VERSION_BUMP=1" >> $GITHUB_ENV
112+
113+
# Update the version in go.mod. This alone ensures there's a diff.
114+
go mod edit -go $TARGET_VERSION
115+
116+
# In the future, "go fix" may make changes to Go code,
117+
# such as to adapt to language changes or API deprecations.
118+
# This is largely a no-op as of Go 1.17, and that's fine.
119+
go fix
120+
git add .
121+
122+
# We don't tidy, because the next step does that.
123+
# Separate commits also help with reviews.
124+
git commit -m "bump go.mod to Go $TARGET_VERSION and run go fix"
125+
fi
126+
- name: go mod tidy (on initial deployment and on new Go version)
127+
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 || env.GO_VERSION_BUMP == 1}}
128+
uses: protocol/[email protected]
129+
with:
130+
working-directory: ${{ env.TARGET_REPO_DIR }}
131+
run: |
132+
go mod tidy
133+
if ! git diff --quiet; then
134+
git add .
135+
git commit -m "run go mod tidy"
136+
fi
137+
- name: gofmt -s (on initial deployment and on new Go version)
138+
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 || env.GO_VERSION_BUMP == 1}}
139+
working-directory: ${{ env.TARGET_REPO_DIR }}
95140
run: |
96-
cd $TARGET_REPO_DIR
97141
gofmt -s -w .
98142
if ! git diff --quiet; then
99143
git add .
100144
git commit -m "run gofmt -s"
101145
fi
102146
- name: Add files
103147
run: |
104-
for f in $(jq -r ".[]" <<< '${{ toJson(github.event.client_payload.files) }}'); do
148+
for f in $(jq -r ".[]" <<< ${{ toJson(github.event.inputs.files) }}); do
105149
echo -e "\nProcessing $f."
106150
# add DO NOT EDIT header
107151
tmp=$(mktemp)
@@ -131,16 +175,15 @@ jobs:
131175
popd > /dev/null
132176
done
133177
- name: Check if we need to create a PR
134-
run: |
135-
cd $TARGET_REPO_DIR
136-
echo "NEEDS_UPDATE=$(git rev-list HEAD...origin/$(git rev-parse --abbrev-ref HEAD) --ignore-submodules --count)" >> $GITHUB_ENV
178+
working-directory: ${{ env.TARGET_REPO_DIR }}
179+
run: echo "NEEDS_UPDATE=$(git rev-list HEAD...origin/$(git rev-parse --abbrev-ref HEAD) --ignore-submodules --count)" >> $GITHUB_ENV
137180
- name: Create Pull Request
138181
if: ${{ env.NEEDS_UPDATE }}
139-
uses: peter-evans/create-pull-request@89a67b1c69299ccc4dcc2253c3e91001adba29b5 # https://github.com/peter-evans/create-pull-request/pull/856
182+
uses: peter-evans/create-pull-request@a3d36d978a8605d71fdb61c96bf0dfd9c9d8f897 # https://github.com/peter-evans/create-pull-request/pull/856
140183
with:
141184
path: ${{ env.TARGET_REPO_DIR }}
142185
title: "sync: update CI config files"
143-
body: Syncing to commit ${{ github.event.client_payload.github_event.head_commit.url }}.
186+
body: Syncing to commit ${{ github.event.inputs.head_commit_url }}.
144187
token: ${{ secrets.WEB3BOT_GITHUB_TOKEN }}
145188
committer: ${{ env.GITHUB_USER }} <${{ env.GITHUB_EMAIL }}>
146189
author: ${{ env.GITHUB_USER }} <${{ env.GITHUB_EMAIL }}>

.github/workflows/dispatch.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ jobs:
3333
strategy:
3434
fail-fast: false
3535
matrix:
36+
# We end up with multiple "dispatch" jobs,
37+
# one per TARGETS "key" chunk above with a "value" array.
38+
# For each "dispatch" job, matrix.cfg.value is an array, like:
39+
#
40+
# [{"target": "repo1", "target": "repo2"}]
41+
#
42+
# The triggered copy-workflow jobs use that final array as their matrix.
43+
# As such, we'll end up with one copy-workflow parallel job per target.
3644
cfg: ${{ fromJson(needs.matrix.outputs.targets) }}
3745
name: Start copy workflow (batch ${{ matrix.cfg.key }})
3846
steps:
39-
- uses: peter-evans/repository-dispatch@ce5485de42c9b2622d2ed064be479e8ed65e76f4 # v1.1.3
47+
- uses: benc-uk/workflow-dispatch@4c044c1613fabbe5250deadc65452d54c4ad4fc7 # v1.1.0
4048
with:
49+
workflow: "Deploy" # "name" attribute of copy-workflow.yml
4150
token: ${{ secrets.WEB3BOT_GITHUB_TOKEN }}
42-
event-type: copy-workflow
43-
client-payload: '{ "github_event": ${{ toJson(github.event) }}, "files": ${{ env.FILES }}, "targets": ${{ toJson(matrix.cfg.value) }} }'
51+
inputs: '{ "head_commit_url": ${{ toJson(github.event.head_commit.url) }}, "files": ${{ toJson(env.FILES) }}, "targets": ${{ toJson(toJson(matrix.cfg.value)) }} }'

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,43 @@ By storing them in a central place (here), and distributing them in an automated
55
1. Consistency: Every participating repository uses the same workflow, ensuring that our code adheres to the same coding standards and is properly tested.
66
2. Maintainability: Workflows change over time. We need to be able to make changes without manually updating dozens of repositories.
77

8+
## Customization
9+
10+
### Additional Setup Steps
11+
12+
Most repositories won't need any customization, and the workflows defined here will just work fine.
13+
Some repositories may require some pre-setup steps to be run before tests (or code checks) can be run. Setup steps for `go-test` are defined in `.github/actions/go-test-setup/action.yml`, and setup steps for `go-check` are defined in `.github/actions/go-check-setup/action.yml`, in the following format:
14+
15+
```yml
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Step 1
20+
shell: bash
21+
run: echo "do some initial setup"
22+
- name: Step 2
23+
shell: bash
24+
run: echo "do some Linux-specific setup"
25+
if: ${{ matrix.os == 'ubuntu' }}
26+
```
27+
28+
These setup steps are run after the repository has been checked out and after Go has been installed, but before any tests or checks are run.
29+
30+
### Configuration
31+
32+
`go-check` contains an optional step that checks that running `go generate` doesn't change any files.
33+
This is useful to make sure that the generated code stays in sync.
34+
35+
This check will be run in repositories that set `gogenerate` to `true` in `.github/workflows/go-check-config.json`:
36+
```json
37+
{
38+
"gogenerate": true
39+
}
40+
```
41+
42+
Note that depending on the code generators used, it might be necessary to [install those first](#additional-setup-steps).
43+
The generators must also be deterministic, to prevent CI from getting different results each time.
44+
845
## Technical Details
946

1047
This repository currently defines two workflows for Go repositories:

templates/.github/workflows/automerge.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030
automerge:
3131
needs: automerge-check
3232
runs-on: ubuntu-latest
33-
if: ${{ needs.automerge-check.outputs.status == 'true' }}
33+
# The check for the user is redundant here, as this job depends on the automerge-check job,
34+
# but it prevents this job from spinning up, just to be skipped shortly after.
35+
if: github.event.pull_request.user.login == 'web3-bot' && needs.automerge-check.outputs.status == 'true'
3436
steps:
3537
- name: Wait on tests
3638
uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2

templates/.github/workflows/go-check.yml

+29-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,28 @@ jobs:
55
unit:
66
runs-on: ubuntu-latest
77
name: All
8+
env:
9+
RUNGOGENERATE: false
810
steps:
911
- uses: actions/checkout@v2
1012
with:
1113
submodules: recursive
1214
- uses: actions/setup-go@v2
1315
with:
14-
go-version: "1.16.x"
16+
go-version: "1.17.x"
17+
- name: Run repo-specific setup
18+
uses: ./.github/actions/go-check-setup
19+
if: hashFiles('./.github/actions/go-check-setup') != ''
20+
- name: Read config
21+
if: hashFiles('./.github/workflows/go-check-config.json') != ''
22+
run: |
23+
if jq -re .gogenerate ./.github/workflows/go-check-config.json; then
24+
echo "RUNGOGENERATE=true" >> $GITHUB_ENV
25+
fi
1526
- name: Install staticcheck
16-
run: go install honnef.co/go/tools/cmd/staticcheck@434f5f3816b358fe468fa83dcba62d794e7fe04b # 2021.1 (v0.2.0)
27+
run: go install honnef.co/go/tools/cmd/staticcheck@df71e5d0e0ed317ebf43e6e59cf919430fa4b8f2 # 2021.1.1 (v0.2.1)
1728
- name: Check that go.mod is tidy
18-
uses: protocol/multiple-go-modules@v1.0
29+
uses: protocol/multiple-go-modules@v1.2
1930
with:
2031
run: |
2132
go mod tidy
@@ -34,14 +45,27 @@ jobs:
3445
fi
3546
- name: go vet
3647
if: ${{ success() || failure() }} # run this step even if the previous one failed
37-
uses: protocol/multiple-go-modules@v1.0
48+
uses: protocol/multiple-go-modules@v1.2
3849
with:
3950
run: go vet ./...
4051
- name: staticcheck
4152
if: ${{ success() || failure() }} # run this step even if the previous one failed
42-
uses: protocol/multiple-go-modules@v1.0
53+
uses: protocol/multiple-go-modules@v1.2
4354
with:
4455
run: |
4556
set -o pipefail
4657
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
58+
- name: go generate
59+
uses: protocol/[email protected]
60+
if: (success() || failure()) && env.RUNGOGENERATE == 'true'
61+
with:
62+
run: |
63+
git clean -fd # make sure there aren't untracked files / directories
64+
go generate ./...
65+
# check if go generate modified or added any files
66+
if ! $(git add . && git diff-index HEAD --exit-code --quiet); then
67+
echo "go generated caused changes to the repository:"
68+
git status --short
69+
exit 1
70+
fi
4771

templates/.github/workflows/go-test.yml

+15-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ jobs:
77
fail-fast: false
88
matrix:
99
os: [ "ubuntu", "windows", "macos" ]
10-
go: [ "1.15.x", "1.16.x" ]
10+
go: [ "1.16.x", "1.17.x" ]
11+
env:
12+
COVERAGES: ""
1113
runs-on: ${{ matrix.os }}-latest
1214
name: ${{ matrix.os}} (go ${{ matrix.go }})
1315
steps:
@@ -21,24 +23,30 @@ jobs:
2123
run: |
2224
go version
2325
go env
26+
- name: Run repo-specific setup
27+
uses: ./.github/actions/go-test-setup
28+
if: hashFiles('./.github/actions/go-test-setup') != ''
2429
- name: Run tests
25-
uses: protocol/multiple-go-modules@v1.0
30+
uses: protocol/multiple-go-modules@v1.2
2631
with:
27-
run: go test -v -coverprofile coverage.txt ./...
32+
run: go test -v -coverprofile module-coverage.txt ./...
2833
- name: Run tests (32 bit)
2934
if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
30-
uses: protocol/multiple-go-modules@v1.0
35+
uses: protocol/multiple-go-modules@v1.2
3136
env:
3237
GOARCH: 386
3338
with:
3439
run: go test -v ./...
3540
- name: Run tests with race detector
3641
if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
37-
uses: protocol/multiple-go-modules@v1.0
42+
uses: protocol/multiple-go-modules@v1.2
3843
with:
3944
run: go test -v -race ./...
45+
- name: Collect coverage files
46+
shell: bash
47+
run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV
4048
- name: Upload coverage to Codecov
41-
uses: codecov/codecov-action@a1ed4b322b4b38cb846afb5a0ebfa17086917d27 # v1.5.0
49+
uses: codecov/codecov-action@51d810878be5422784e86451c0e7c14e5860ec47 # v2.0.2
4250
with:
43-
file: coverage.txt
51+
files: '${{ env.COVERAGES }}'
4452
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}

0 commit comments

Comments
 (0)