Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
526400f
move config*.json files to configs directory
galargh Dec 7, 2021
f727003
rename configs/*.json
galargh Dec 8, 2021
f434f15
make checks aware of all the configs/*.json
galargh Dec 7, 2021
496348f
turn configs into objects with repositories key
galargh Dec 7, 2021
67da4b2
make files part of the config
galargh Dec 7, 2021
b9aaa52
move language specific copy-workflow setup to actions
galargh Dec 7, 2021
02436cf
make dispatch workflow support more than one config json
galargh Dec 7, 2021
0d71b9e
create fewer batches if possible
galargh Dec 7, 2021
0828267
set up copy-workflow actions properly
galargh Dec 8, 2021
1dfeb94
extract defaults from config separately
galargh Dec 8, 2021
16e4ca8
bring back double toJson
galargh Dec 8, 2021
dbe2f9c
use copy-workflow actions from same branch
galargh Dec 8, 2021
f5cf5ab
use compact json representation for storing FILES
galargh Dec 8, 2021
6955318
fix files and local actions
galargh Dec 8, 2021
c95cbff
run actions from template repo
galargh Dec 8, 2021
5c86ae0
add missing shell property to actions
galargh Dec 8, 2021
0b3c5cb
add configs README
galargh Dec 8, 2021
07f9202
set deploy_versioning=true for go repositories
galargh Dec 15, 2021
9fdc4eb
address review comments
galargh Dec 15, 2021
60d1f29
restore hardcoded template-repo reference
galargh Dec 15, 2021
a71f87a
add section on config testing
galargh Dec 15, 2021
0f34080
fix batches creation
galargh Dec 16, 2021
b2c1dd9
fix command that produces batches
galargh Dec 16, 2021
664f8b7
fix needs update logic
galargh Dec 16, 2021
34022b2
Merge remote-tracking branch 'origin/master' into testing-js
galargh Jan 7, 2022
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
18 changes: 10 additions & 8 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash

tmp=$(mktemp)
git show :config.json > $tmp
status=0
if ! output=$(.github/workflows/check-config.sh $tmp); then
echo "$output"
status=1
fi
rm $tmp
for config in configs/*.json; do
tmp=$(mktemp)
git show :$config > $tmp
status=0
if ! output=$(.github/workflows/check-config.sh $tmp $config); then
echo "$output"
status=1
fi
rm $tmp
done

exit $status
64 changes: 64 additions & 0 deletions .github/actions/copy-workflow-go/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: copy workflow go
description: Copy workflow steps specific to go

runs:
using: "composite"
steps:
- uses: actions/setup-go@v2
with:
# This should be the same Go version we use in the go-check workflow.
# go mod tidy, go vet, staticcheck and gofmt might behave differently depending on the version.
go-version: "1.17.x"
- name: bump go.mod go version if needed
uses: protocol/[email protected]
with:
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
# We want our modules to support two Go versions at a time.
# As of August 2021, Go 1.17 is the latest stable.
# go.mod's Go version declares the language version being used.
# As such, it has to be the minimum of all Go versions supported.
# Bump this every six months, as new Go versions come out.
TARGET_VERSION=1.16

# Note that the "<" comparison doesn't understand semver,
# but it should be good enough for the foreseeable future.
CURRENT_VERSION=$(go list -m -f {{.GoVersion}})

if [[ $CURRENT_VERSION < $TARGET_VERSION ]]; then
echo "GO_VERSION_BUMP=1" >> $GITHUB_ENV

# Update the version in go.mod. This alone ensures there's a diff.
go mod edit -go $TARGET_VERSION

# In the future, "go fix" may make changes to Go code,
# such as to adapt to language changes or API deprecations.
# This is largely a no-op as of Go 1.17, and that's fine.
go fix ./...
git add .

# We don't tidy, because the next step does that.
# Separate commits also help with reviews.
git commit -m "bump go.mod to Go $TARGET_VERSION and run go fix"
fi
- name: go mod tidy (on initial workflow deployment and on new Go version)
if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 || env.GO_VERSION_BUMP == 1}}
uses: protocol/[email protected]
with:
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
go mod tidy
if ! git diff --quiet; then
git add .
git commit -m "run go mod tidy"
fi
- name: gofmt -s (on initial workflow deployment and on new Go version)
if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 || env.GO_VERSION_BUMP == 1}}
working-directory: ${{ env.TARGET_REPO_DIR }}
shell: bash
run: |
gofmt -s -w .
if ! git diff --quiet; then
git add .
git commit -m "run gofmt -s"
fi
18 changes: 18 additions & 0 deletions .github/actions/copy-workflow-versioning/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: copy workflow versioning
description: Copy workflow steps specific to versioning

runs:
using: "composite"
steps:
- name: add version.json file (in order to deploy versioning workflows)
if: hashFiles(format('{0}/version.json', env.TARGET_REPO_DIR)) == ''
working-directory: ${{ env.TARGET_REPO_DIR }}
shell: bash
run: |
git fetch origin --unshallow # we need the entire commit history
version=$(git describe --tags --abbrev=0 || true) # highest released version on current branch
if [[ -n "$version" ]]; then # only deply version.json if there's at least one release
printf '{"version": "%s"}' "$version" | jq . > version.json
git add version.json
git commit -m "add version.json file"
fi
3 changes: 1 addition & 2 deletions .github/workflows/check-3rd-party.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
on:
pull_request:
paths-ignore:
- 'config.json'
- 'config-testing.json'
- 'configs/*.json'

name: Check 3rd Party

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/check-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
set -e

file=$1
source=${2:-$file}
entries=$(mktemp)
entries_sorted=$(mktemp)

jq -r ".[].target" $file > $entries
jq -r ".repositories[].target" $file > $entries
sort -u $entries > $entries_sorted
status=0
if ! output=$(diff -y $entries $entries_sorted); then
echo "Targets in config.json not sorted alphabetically:"
echo "Targets in $source not sorted alphabetically:"
echo "$output"
status=1
fi
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/check-config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
pull_request:
paths:
- 'config.json'
- 'configs/*.json'

name: Check Config

Expand All @@ -12,5 +12,10 @@ jobs:
targets: ${{ steps.set-matrix.outputs.targets }}
steps:
- uses: actions/checkout@v2
- name: check if config.json is sorted alphabetically
run: .github/workflows/check-config.sh config.json
- name: check if config files are sorted alphabetically
run: |
for config in configs/*.json; do
echo "::group::$config"
.github/workflows/check-config.sh $config
echo "::endgroup::"
done
123 changes: 34 additions & 89 deletions .github/workflows/copy-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ on:
head_commit_url:
description: "github.event.head_commit.url of the dispatcher"
required: true
files:
description: "List of files to deploy"
required: true
targets:
description: "List of repositories to deploy to"
required: true
Expand All @@ -28,7 +25,7 @@ jobs:
TEMPLATE_REPO_DIR: "template-repo"
TEMPLATE_DIR: "templates"
NEEDS_UPDATE: 0
INITIAL_TEST_DEPLOYMENT: 0
INITIAL_WORKFLOW_DEPLOYMENT: 0
GO_VERSION_BUMP: 0
FILES: ""
GITHUB_USER: "web3-bot"
Expand All @@ -48,11 +45,6 @@ jobs:
uses: actions/checkout@v2
with:
path: ${{ env.TEMPLATE_REPO_DIR }}
- uses: actions/setup-go@v2
with:
# This should be the same Go version we use in the go-check workflow.
# go mod tidy, go vet, staticcheck and gofmt might behave differently depending on the version.
go-version: "1.17.x"
- name: determine GitHub default branch
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
Expand All @@ -63,105 +55,58 @@ jobs:
run: |
git config user.name ${{ env.GITHUB_USER }}
git config user.email ${{ env.GITHUB_EMAIL }}
- name: is initial test workflow deployment
- name: determine files to add
# By setting the environment variable, it's possible to programmatically add / modify this list.
# See https://github.com/protocol/.github/blob/38135c75e47839623bf9b2748275d8c6167a8fa8/.github/workflows/copy-workflow.yml#L163-L168 for an example, how we used to make use of this.
run: |
if [[ ! -f $TARGET_REPO_DIR/.github/workflows/go-test.yml ]]; then
echo "INITIAL_TEST_DEPLOYMENT=1" >> $GITHUB_ENV
fi
- name: remove Travis (on initial deployment)
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 }}
files=${{ toJson(toJson(matrix.cfg.files)) }}
files=$(echo -e "$files" | jq -c '.')
echo "FILES=$files" >> $GITHUB_ENV
- name: is initial workflow deployment
# INITIAL_WORKFLOW_DEPLOYMENT=1 iff none of the files in the target repository exist yet
run: |
initial_workflow_deployment=1
for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do
if [[ -f $TARGET_REPO_DIR/$f ]]; then
initial_workflow_deployment=0
break
fi
done
echo "INITIAL_WORKFLOW_DEPLOYMENT=$initial_workflow_deployment" >> $GITHUB_ENV
- name: remove Travis (on initial workflow deployment)
if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 }}
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
if [[ -f .travis.yml ]]; then
git rm .travis.yml
git commit -m "disable Travis"
fi
- name: remove CircleCI (on initial deployment)
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 }}
- name: remove CircleCI (on initial workflow deployment)
if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 }}
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
if [[ -d .circleci ]]; then
git rm -r .circleci
git commit -m "disable CircleCI"
fi
- name: remove gx (on initial deployment)
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 }}
- name: remove gx (on initial workflow deployment)
if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 }}
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
if [[ -d .gx ]]; then
git rm -r .gx
git commit -m "remove .gx"
fi
- name: add version.json file (in order to deploy versioning workflows)
if: hashFiles(format('{0}/version.json', env.TARGET_REPO_DIR)) == ''
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
git fetch origin --unshallow # we need the entire commit history
version=$(git describe --tags --abbrev=0 || true) # highest released version on current branch
if [[ -n "$version" ]]; then # only deply version.json if there's at least one release
printf '{"version": "%s"}' "$version" | jq . > version.json
git add version.json
git commit -m "add version.json file"
fi
- name: bump go.mod go version if needed
uses: protocol/[email protected]
with:
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
# We want our modules to support two Go versions at a time.
# As of August 2021, Go 1.17 is the latest stable.
# go.mod's Go version declares the language version being used.
# As such, it has to be the minimum of all Go versions supported.
# Bump this every six months, as new Go versions come out.
TARGET_VERSION=1.16

# Note that the "<" comparison doesn't understand semver,
# but it should be good enough for the foreseeable future.
CURRENT_VERSION=$(go list -m -f {{.GoVersion}})

if [[ $CURRENT_VERSION < $TARGET_VERSION ]]; then
echo "GO_VERSION_BUMP=1" >> $GITHUB_ENV

# Update the version in go.mod. This alone ensures there's a diff.
go mod edit -go $TARGET_VERSION

# In the future, "go fix" may make changes to Go code,
# such as to adapt to language changes or API deprecations.
# This is largely a no-op as of Go 1.17, and that's fine.
go fix ./...
git add .

# We don't tidy, because the next step does that.
# Separate commits also help with reviews.
git commit -m "bump go.mod to Go $TARGET_VERSION and run go fix"
fi
- name: go mod tidy (on initial deployment and on new Go version)
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 || env.GO_VERSION_BUMP == 1}}
uses: protocol/[email protected]
with:
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
go mod tidy
if ! git diff --quiet; then
git add .
git commit -m "run go mod tidy"
fi
- name: gofmt -s (on initial deployment and on new Go version)
if: ${{ env.INITIAL_TEST_DEPLOYMENT == 1 || env.GO_VERSION_BUMP == 1}}
working-directory: ${{ env.TARGET_REPO_DIR }}
run: |
gofmt -s -w .
if ! git diff --quiet; then
git add .
git commit -m "run gofmt -s"
fi
- name: determine files to add
# By setting the environment variable, it's possible to programmatically add / modify this list.
# See https://github.com/protocol/.github/blob/38135c75e47839623bf9b2748275d8c6167a8fa8/.github/workflows/copy-workflow.yml#L163-L168 for an example, how we used to make use of this.
run: echo "FILES=${{ toJson(github.event.inputs.files) }}" >> $GITHUB_ENV
- name: Run steps specific to go
if: matrix.cfg.deploy_go
# use of ${{ env.TEMPATE_REPO_DIR }} is not allowed here
uses: ./template-repo/.github/actions/copy-workflow-go
- name: Run steps specific to versioning
if: matrix.cfg.deploy_versioning
uses: ./template-repo/.github/actions/copy-workflow-versioning
- name: Add files
run: |
for f in $(jq -r ".[]" <<< ${{ toJson(env.FILES) }}); do
for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do
echo -e "\nProcessing $f."
# add DO NOT EDIT header
tmp=$(mktemp)
Expand Down Expand Up @@ -194,9 +139,9 @@ jobs:
done
- name: Check if we need to create a PR
working-directory: ${{ env.TARGET_REPO_DIR }}
run: echo "NEEDS_UPDATE=$(git rev-list HEAD...origin/$(git rev-parse --abbrev-ref HEAD) --ignore-submodules --count)" >> $GITHUB_ENV
run: echo "NEEDS_UPDATE=$(git rev-list HEAD...origin/$(git rev-parse --abbrev-ref HEAD) --ignore-submodules --count 2> /dev/null || echo 1)" >> $GITHUB_ENV
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice one. This is a lot better than working with fake bools (strings).

- name: Create Pull Request
if: ${{ env.NEEDS_UPDATE }}
if: ${{ env.NEEDS_UPDATE != 0 }}
uses: peter-evans/create-pull-request@83dbed188f76ab04433c639ec214df65e26bc15c # https://github.com/peter-evans/create-pull-request/pull/856
with:
path: ${{ env.TARGET_REPO_DIR }}
Expand Down
Loading