This repository was archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Prepare copy-workflow for setting up unified CI for JS repos #239
Merged
Merged
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 f727003
rename configs/*.json
galargh f434f15
make checks aware of all the configs/*.json
galargh 496348f
turn configs into objects with repositories key
galargh 67da4b2
make files part of the config
galargh b9aaa52
move language specific copy-workflow setup to actions
galargh 02436cf
make dispatch workflow support more than one config json
galargh 0d71b9e
create fewer batches if possible
galargh 0828267
set up copy-workflow actions properly
galargh 1dfeb94
extract defaults from config separately
galargh 16e4ca8
bring back double toJson
galargh dbe2f9c
use copy-workflow actions from same branch
galargh f5cf5ab
use compact json representation for storing FILES
galargh 6955318
fix files and local actions
galargh c95cbff
run actions from template repo
galargh 5c86ae0
add missing shell property to actions
galargh 0b3c5cb
add configs README
galargh 07f9202
set deploy_versioning=true for go repositories
galargh 9fdc4eb
address review comments
galargh 60d1f29
restore hardcoded template-repo reference
galargh a71f87a
add section on config testing
galargh 0f34080
fix batches creation
galargh b2c1dd9
fix command that produces batches
galargh 664f8b7
fix needs update logic
galargh 34022b2
Merge remote-tracking branch 'origin/master' into testing-js
galargh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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" | ||
|
|
@@ -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: | | ||
|
|
@@ -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 | ||
galargh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - 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) | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }} | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.