From 526400f59297dbeddfed095d5ad662860b03817e Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 7 Dec 2021 13:24:35 +0100 Subject: [PATCH 01/24] move config*.json files to configs directory --- .githooks/pre-commit | 2 +- .github/workflows/check-3rd-party.yml | 4 ++-- .github/workflows/check-config.sh | 2 +- .github/workflows/check-config.yml | 6 +++--- .github/workflows/dispatch.yml | 4 ++-- .github/workflows/stale-repos.yml | 2 +- README.md | 2 +- config-testing.json => configs/config-testing.json | 0 config.json => configs/config.json | 0 9 files changed, 11 insertions(+), 11 deletions(-) rename config-testing.json => configs/config-testing.json (100%) rename config.json => configs/config.json (100%) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index e4097f58..da7231cb 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,7 +1,7 @@ #!/bin/bash tmp=$(mktemp) -git show :config.json > $tmp +git show :configs/go.json > $tmp status=0 if ! output=$(.github/workflows/check-config.sh $tmp); then echo "$output" diff --git a/.github/workflows/check-3rd-party.yml b/.github/workflows/check-3rd-party.yml index 5c848a78..dc248767 100644 --- a/.github/workflows/check-3rd-party.yml +++ b/.github/workflows/check-3rd-party.yml @@ -1,8 +1,8 @@ on: pull_request: paths-ignore: - - 'config.json' - - 'config-testing.json' + - 'configs/go.json' + - 'configs/testing.json' name: Check 3rd Party diff --git a/.github/workflows/check-config.sh b/.github/workflows/check-config.sh index 701726d8..b66ab09d 100755 --- a/.github/workflows/check-config.sh +++ b/.github/workflows/check-config.sh @@ -10,7 +10,7 @@ jq -r ".[].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 configs/go.json not sorted alphabetically:" echo "$output" status=1 fi diff --git a/.github/workflows/check-config.yml b/.github/workflows/check-config.yml index 64997921..feabf448 100644 --- a/.github/workflows/check-config.yml +++ b/.github/workflows/check-config.yml @@ -1,7 +1,7 @@ on: pull_request: paths: - - 'config.json' + - 'configs/go.json' name: Check Config @@ -12,5 +12,5 @@ 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 configs/go.json is sorted alphabetically + run: .github/workflows/check-config.sh configs/go.json diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index d7e78e02..5b189fba 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -24,9 +24,9 @@ jobs: - uses: actions/checkout@v2 - id: set-matrix run: | - CONFIG=config.json + CONFIG=configs/go.json if [[ $GITHUB_REF == refs/heads/testing ]]; then - CONFIG=config-testing.json + CONFIG=configs/testing.json fi TARGETS=$(jq '. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})' $CONFIG | jq -sc '. | to_entries') echo "::set-output name=targets::$TARGETS" diff --git a/.github/workflows/stale-repos.yml b/.github/workflows/stale-repos.yml index bae027ba..bf73d55f 100644 --- a/.github/workflows/stale-repos.yml +++ b/.github/workflows/stale-repos.yml @@ -11,7 +11,7 @@ jobs: - name: find deleted / archived repositories run: | status=0 - for repo in $(jq -r '.[].target' config.json); do + for repo in $(jq -r '.[].target' configs/go.json); do exists=true output=$(curl -s -f -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$repo") || exists=false if ! $exists; then diff --git a/README.md b/README.md index d5a61602..9159f46c 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ In order to help with the distribution of these workflows, this repository defin ## Usage -Workflows are distributed to all repositories listed in [config.json](config.json). +Workflows are distributed to all repositories listed in [configs/go.json](configs/go.json). If you want your project to participle, please send a PR! diff --git a/config-testing.json b/configs/config-testing.json similarity index 100% rename from config-testing.json rename to configs/config-testing.json diff --git a/config.json b/configs/config.json similarity index 100% rename from config.json rename to configs/config.json From f7270030553d221d42f6af09e3550162c0b3f602 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 13:42:47 +0100 Subject: [PATCH 02/24] rename configs/*.json --- configs/{config.json => go.json} | 0 configs/{config-testing.json => testing.json} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename configs/{config.json => go.json} (100%) rename configs/{config-testing.json => testing.json} (100%) diff --git a/configs/config.json b/configs/go.json similarity index 100% rename from configs/config.json rename to configs/go.json diff --git a/configs/config-testing.json b/configs/testing.json similarity index 100% rename from configs/config-testing.json rename to configs/testing.json From f434f151fb2e91fef49ca1ab3d65d44b68f19a65 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 7 Dec 2021 13:49:46 +0100 Subject: [PATCH 03/24] make checks aware of all the configs/*.json --- .githooks/pre-commit | 19 +++++++++++-------- .github/workflows/check-3rd-party.yml | 3 +-- .github/workflows/check-config.sh | 2 +- .github/workflows/check-config.yml | 9 ++++++--- .github/workflows/stale-repos.yml | 27 ++++++++++++++------------- 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index da7231cb..796b8fe9 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,12 +1,15 @@ #!/bin/bash -tmp=$(mktemp) -git show :configs/go.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); then + echo "$tmp contains git show :$config output." + echo "$output" + status=1 + fi + rm $tmp +done exit $status diff --git a/.github/workflows/check-3rd-party.yml b/.github/workflows/check-3rd-party.yml index dc248767..339793df 100644 --- a/.github/workflows/check-3rd-party.yml +++ b/.github/workflows/check-3rd-party.yml @@ -1,8 +1,7 @@ on: pull_request: paths-ignore: - - 'configs/go.json' - - 'configs/testing.json' + - 'configs/*.json' name: Check 3rd Party diff --git a/.github/workflows/check-config.sh b/.github/workflows/check-config.sh index b66ab09d..4c164b26 100755 --- a/.github/workflows/check-config.sh +++ b/.github/workflows/check-config.sh @@ -10,7 +10,7 @@ jq -r ".[].target" $file > $entries sort -u $entries > $entries_sorted status=0 if ! output=$(diff -y $entries $entries_sorted); then - echo "Targets in configs/go.json not sorted alphabetically:" + echo "Targets in $file not sorted alphabetically:" echo "$output" status=1 fi diff --git a/.github/workflows/check-config.yml b/.github/workflows/check-config.yml index feabf448..918c58d8 100644 --- a/.github/workflows/check-config.yml +++ b/.github/workflows/check-config.yml @@ -1,7 +1,7 @@ on: pull_request: paths: - - 'configs/go.json' + - 'configs/*.json' name: Check Config @@ -12,5 +12,8 @@ jobs: targets: ${{ steps.set-matrix.outputs.targets }} steps: - uses: actions/checkout@v2 - - name: check if configs/go.json is sorted alphabetically - run: .github/workflows/check-config.sh configs/go.json + - name: check if configs/*.json is sorted alphabetically + run: | + for config in configs/*.json; do + .github/workflows/check-config.sh $config + done diff --git a/.github/workflows/stale-repos.yml b/.github/workflows/stale-repos.yml index bf73d55f..d1ad69a2 100644 --- a/.github/workflows/stale-repos.yml +++ b/.github/workflows/stale-repos.yml @@ -11,18 +11,19 @@ jobs: - name: find deleted / archived repositories run: | status=0 - for repo in $(jq -r '.[].target' configs/go.json); do - exists=true - output=$(curl -s -f -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$repo") || exists=false - if ! $exists; then - echo "Repository $repo does not exist." - status=1 - continue - fi - if [[ $(echo "$output" | jq ".archived") == "true" ]]; then - echo "Repository $repo is archived." - status=1 - fi + for config in configs/*.json; do + for repo in $(jq -r '.[].target' $config); do + exists=true + output=$(curl -s -f -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$repo") || exists=false + if ! $exists; then + echo "Repository $repo does not exist." + status=1 + continue + fi + if [[ $(echo "$output" | jq ".archived") == "true" ]]; then + echo "Repository $repo is archived." + status=1 + fi + done done exit $status - From 496348f007177fa9557b94b9b212d5b1b27ffdf9 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 7 Dec 2021 15:05:09 +0100 Subject: [PATCH 04/24] turn configs into objects with repositories key --- .github/workflows/check-config.sh | 2 +- .github/workflows/dispatch.yml | 4 +- .github/workflows/stale-repos.yml | 2 +- configs/go.json | 358 +++++++++++++++--------------- configs/testing.json | 8 +- 5 files changed, 189 insertions(+), 185 deletions(-) diff --git a/.github/workflows/check-config.sh b/.github/workflows/check-config.sh index 4c164b26..53887d41 100755 --- a/.github/workflows/check-config.sh +++ b/.github/workflows/check-config.sh @@ -6,7 +6,7 @@ file=$1 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 diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 5b189fba..2f99bc65 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -28,7 +28,7 @@ jobs: if [[ $GITHUB_REF == refs/heads/testing ]]; then CONFIG=configs/testing.json fi - TARGETS=$(jq '. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})' $CONFIG | jq -sc '. | to_entries') + TARGETS=$(jq '.repositories | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})' $CONFIG | jq -sc '. | to_entries') echo "::set-output name=targets::$TARGETS" dispatch: needs: [ matrix ] @@ -40,7 +40,7 @@ jobs: # one per TARGETS "key" chunk above with a "value" array. # For each "dispatch" job, matrix.cfg.value is an array, like: # - # [{"target": "repo1", "target": "repo2"}] + # [{"target": "repo1"}, {"target": "repo2"}] # # The triggered copy-workflow jobs use that final array as their matrix. # As such, we'll end up with one copy-workflow parallel job per target. diff --git a/.github/workflows/stale-repos.yml b/.github/workflows/stale-repos.yml index d1ad69a2..89baa9fe 100644 --- a/.github/workflows/stale-repos.yml +++ b/.github/workflows/stale-repos.yml @@ -12,7 +12,7 @@ jobs: run: | status=0 for config in configs/*.json; do - for repo in $(jq -r '.[].target' $config); do + for repo in $(jq -r '.repositories[].target' $config); do exists=true output=$(curl -s -f -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$repo") || exists=false if ! $exists; then diff --git a/configs/go.json b/configs/go.json index 9efe50ee..94f60a88 100644 --- a/configs/go.json +++ b/configs/go.json @@ -1,178 +1,180 @@ -[ - { "target": "filecoin-project/go-amt-ipld" }, - { "target": "filecoin-project/go-bitfield" }, - { "target": "filecoin-project/go-commp-utils" }, - { "target": "filecoin-project/go-fil-commp-hashhash" }, - { "target": "filecoin-project/go-hamt-ipld" }, - { "target": "filecoin-project/go-indexer-core" }, - { "target": "filecoin-project/go-legs" }, - { "target": "filecoin-project/indexer-reference-provider" }, - { "target": "filecoin-project/storetheindex" }, - { "target": "filecoin-shipyard/js-lotus-client-schema" }, - { "target": "ipfs-shipyard/dnslink-dnsimple" }, - { "target": "ipfs-shipyard/git-remote-ipld" }, - { "target": "ipfs-shipyard/ipfs-counter" }, - { "target": "ipfs-shipyard/w3rc" }, - { "target": "ipfs/bbloom" }, - { "target": "ipfs/go-bitfield" }, - { "target": "ipfs/go-bitswap" }, - { "target": "ipfs/go-block-format" }, - { "target": "ipfs/go-blockservice" }, - { "target": "ipfs/go-bs-sqlite3" }, - { "target": "ipfs/go-cid" }, - { "target": "ipfs/go-cidutil" }, - { "target": "ipfs/go-dagwriter" }, - { "target": "ipfs/go-datastore" }, - { "target": "ipfs/go-detect-race" }, - { "target": "ipfs/go-dnslink" }, - { "target": "ipfs/go-ds-badger" }, - { "target": "ipfs/go-ds-badger2" }, - { "target": "ipfs/go-ds-bitcask" }, - { "target": "ipfs/go-ds-crdt" }, - { "target": "ipfs/go-ds-flatfs" }, - { "target": "ipfs/go-ds-leveldb" }, - { "target": "ipfs/go-ds-measure" }, - { "target": "ipfs/go-ds-pebble" }, - { "target": "ipfs/go-ds-redis" }, - { "target": "ipfs/go-ds-s3" }, - { "target": "ipfs/go-ds-sql" }, - { "target": "ipfs/go-fetcher" }, - { "target": "ipfs/go-filestore" }, - { "target": "ipfs/go-fs-lock" }, - { "target": "ipfs/go-graphsync" }, - { "target": "ipfs/go-ipfs-api" }, - { "target": "ipfs/go-ipfs-blockstore" }, - { "target": "ipfs/go-ipfs-blocksutil" }, - { "target": "ipfs/go-ipfs-chunker" }, - { "target": "ipfs/go-ipfs-cmds" }, - { "target": "ipfs/go-ipfs-config" }, - { "target": "ipfs/go-ipfs-delay" }, - { "target": "ipfs/go-ipfs-ds-help" }, - { "target": "ipfs/go-ipfs-example-plugin" }, - { "target": "ipfs/go-ipfs-exchange-interface" }, - { "target": "ipfs/go-ipfs-exchange-offline" }, - { "target": "ipfs/go-ipfs-files" }, - { "target": "ipfs/go-ipfs-http-client" }, - { "target": "ipfs/go-ipfs-keystore" }, - { "target": "ipfs/go-ipfs-pinner" }, - { "target": "ipfs/go-ipfs-posinfo" }, - { "target": "ipfs/go-ipfs-pq" }, - { "target": "ipfs/go-ipfs-provider" }, - { "target": "ipfs/go-ipfs-routing" }, - { "target": "ipfs/go-ipfs-util" }, - { "target": "ipfs/go-ipld-cbor" }, - { "target": "ipfs/go-ipld-format" }, - { "target": "ipfs/go-ipld-git" }, - { "target": "ipfs/go-ipld-legacy" }, - { "target": "ipfs/go-ipns" }, - { "target": "ipfs/go-log" }, - { "target": "ipfs/go-merkledag" }, - { "target": "ipfs/go-metrics-interface" }, - { "target": "ipfs/go-metrics-prometheus" }, - { "target": "ipfs/go-mfs" }, - { "target": "ipfs/go-namesys" }, - { "target": "ipfs/go-path" }, - { "target": "ipfs/go-peertaskqueue" }, - { "target": "ipfs/go-qringbuf" }, - { "target": "ipfs/go-todocounter" }, - { "target": "ipfs/go-unixfs" }, - { "target": "ipfs/go-unixfsnode" }, - { "target": "ipfs/go-verifcid" }, - { "target": "ipfs/hang-fds" }, - { "target": "ipfs/interface-go-ipfs-core" }, - { "target": "ipfs/ipfs-ds-convert" }, - { "target": "ipfs/ipfs-update" }, - { "target": "ipfs/ipget" }, - { "target": "ipfs/iptb" }, - { "target": "ipfs/iptb-plugins" }, - { "target": "ipfs/pinbot-irc" }, - { "target": "ipfs/tar-utils" }, - { "target": "ipld/codec-fixtures" }, - { "target": "ipld/go-car" }, - { "target": "ipld/go-codec-dagpb" }, - { "target": "ipld/go-ipld-adl-hamt" }, - { "target": "ipld/go-ipld-btc" }, - { "target": "ipld/go-ipld-graphql" }, - { "target": "ipld/go-ipld-prime-proto" }, - { "target": "ipld/go-ipld-schema" }, - { "target": "ipld/go-ipld-selector-text-lite" }, - { "target": "ipld/go-ipldtool" }, - { "target": "ipld/go-storethehash" }, - { "target": "libp2p/dht-tracer1" }, - { "target": "libp2p/dht-utils" }, - { "target": "libp2p/go-addr-util" }, - { "target": "libp2p/go-buffer-pool" }, - { "target": "libp2p/go-cidranger" }, - { "target": "libp2p/go-composable-routing" }, - { "target": "libp2p/go-conn-security-multistream" }, - { "target": "libp2p/go-doh-resolver" }, - { "target": "libp2p/go-eventbus" }, - { "target": "libp2p/go-flow-metrics" }, - { "target": "libp2p/go-libp2p" }, - { "target": "libp2p/go-libp2p-asn-util" }, - { "target": "libp2p/go-libp2p-autonat" }, - { "target": "libp2p/go-libp2p-backoff" }, - { "target": "libp2p/go-libp2p-blankhost" }, - { "target": "libp2p/go-libp2p-circuit" }, - { "target": "libp2p/go-libp2p-connmgr" }, - { "target": "libp2p/go-libp2p-consensus" }, - { "target": "libp2p/go-libp2p-core" }, - { "target": "libp2p/go-libp2p-daemon" }, - { "target": "libp2p/go-libp2p-discovery" }, - { "target": "libp2p/go-libp2p-gorpc" }, - { "target": "libp2p/go-libp2p-gostream" }, - { "target": "libp2p/go-libp2p-http" }, - { "target": "libp2p/go-libp2p-introspector" }, - { "target": "libp2p/go-libp2p-kad-dht" }, - { "target": "libp2p/go-libp2p-kbucket" }, - { "target": "libp2p/go-libp2p-loggables" }, - { "target": "libp2p/go-libp2p-mplex" }, - { "target": "libp2p/go-libp2p-nat" }, - { "target": "libp2p/go-libp2p-netutil" }, - { "target": "libp2p/go-libp2p-noise" }, - { "target": "libp2p/go-libp2p-peerstore" }, - { "target": "libp2p/go-libp2p-pnet" }, - { "target": "libp2p/go-libp2p-pubsub-router" }, - { "target": "libp2p/go-libp2p-pubsub-tracer" }, - { "target": "libp2p/go-libp2p-quic-transport" }, - { "target": "libp2p/go-libp2p-raft" }, - { "target": "libp2p/go-libp2p-record" }, - { "target": "libp2p/go-libp2p-relay-daemon" }, - { "target": "libp2p/go-libp2p-routing-helpers" }, - { "target": "libp2p/go-libp2p-swarm" }, - { "target": "libp2p/go-libp2p-testing" }, - { "target": "libp2p/go-libp2p-tls" }, - { "target": "libp2p/go-libp2p-transport-upgrader" }, - { "target": "libp2p/go-libp2p-webrtc-direct" }, - { "target": "libp2p/go-libp2p-xor" }, - { "target": "libp2p/go-libp2p-yamux" }, - { "target": "libp2p/go-mplex" }, - { "target": "libp2p/go-msgio" }, - { "target": "libp2p/go-nat" }, - { "target": "libp2p/go-netroute" }, - { "target": "libp2p/go-openssl" }, - { "target": "libp2p/go-reuseport" }, - { "target": "libp2p/go-reuseport-transport" }, - { "target": "libp2p/go-routing-language" }, - { "target": "libp2p/go-smart-record" }, - { "target": "libp2p/go-sockaddr" }, - { "target": "libp2p/go-socket-activation" }, - { "target": "libp2p/go-stream-muxer-multistream" }, - { "target": "libp2p/go-tcp-transport" }, - { "target": "libp2p/go-ws-transport" }, - { "target": "libp2p/go-yamux" }, - { "target": "libp2p/hydra-booster" }, - { "target": "libp2p/repl" }, - { "target": "libp2p/zeroconf" }, - { "target": "multiformats/go-base32" }, - { "target": "multiformats/go-base36" }, - { "target": "multiformats/go-multiaddr" }, - { "target": "multiformats/go-multiaddr-dns" }, - { "target": "multiformats/go-multiaddr-fmt" }, - { "target": "multiformats/go-multibase" }, - { "target": "multiformats/go-multicodec" }, - { "target": "multiformats/go-multihash" }, - { "target": "multiformats/go-multistream" }, - { "target": "multiformats/go-varint" }, - { "target": "multiformats/ma-pipe" } -] +{ + "repositories": [ + { "target": "filecoin-project/go-amt-ipld" }, + { "target": "filecoin-project/go-bitfield" }, + { "target": "filecoin-project/go-commp-utils" }, + { "target": "filecoin-project/go-fil-commp-hashhash" }, + { "target": "filecoin-project/go-hamt-ipld" }, + { "target": "filecoin-project/go-indexer-core" }, + { "target": "filecoin-project/go-legs" }, + { "target": "filecoin-project/indexer-reference-provider" }, + { "target": "filecoin-project/storetheindex" }, + { "target": "filecoin-shipyard/js-lotus-client-schema" }, + { "target": "ipfs-shipyard/dnslink-dnsimple" }, + { "target": "ipfs-shipyard/git-remote-ipld" }, + { "target": "ipfs-shipyard/ipfs-counter" }, + { "target": "ipfs-shipyard/w3rc" }, + { "target": "ipfs/bbloom" }, + { "target": "ipfs/go-bitfield" }, + { "target": "ipfs/go-bitswap" }, + { "target": "ipfs/go-block-format" }, + { "target": "ipfs/go-blockservice" }, + { "target": "ipfs/go-bs-sqlite3" }, + { "target": "ipfs/go-cid" }, + { "target": "ipfs/go-cidutil" }, + { "target": "ipfs/go-dagwriter" }, + { "target": "ipfs/go-datastore" }, + { "target": "ipfs/go-detect-race" }, + { "target": "ipfs/go-dnslink" }, + { "target": "ipfs/go-ds-badger" }, + { "target": "ipfs/go-ds-badger2" }, + { "target": "ipfs/go-ds-bitcask" }, + { "target": "ipfs/go-ds-crdt" }, + { "target": "ipfs/go-ds-flatfs" }, + { "target": "ipfs/go-ds-leveldb" }, + { "target": "ipfs/go-ds-measure" }, + { "target": "ipfs/go-ds-pebble" }, + { "target": "ipfs/go-ds-redis" }, + { "target": "ipfs/go-ds-s3" }, + { "target": "ipfs/go-ds-sql" }, + { "target": "ipfs/go-fetcher" }, + { "target": "ipfs/go-filestore" }, + { "target": "ipfs/go-fs-lock" }, + { "target": "ipfs/go-graphsync" }, + { "target": "ipfs/go-ipfs-api" }, + { "target": "ipfs/go-ipfs-blockstore" }, + { "target": "ipfs/go-ipfs-blocksutil" }, + { "target": "ipfs/go-ipfs-chunker" }, + { "target": "ipfs/go-ipfs-cmds" }, + { "target": "ipfs/go-ipfs-config" }, + { "target": "ipfs/go-ipfs-delay" }, + { "target": "ipfs/go-ipfs-ds-help" }, + { "target": "ipfs/go-ipfs-example-plugin" }, + { "target": "ipfs/go-ipfs-exchange-interface" }, + { "target": "ipfs/go-ipfs-exchange-offline" }, + { "target": "ipfs/go-ipfs-files" }, + { "target": "ipfs/go-ipfs-http-client" }, + { "target": "ipfs/go-ipfs-keystore" }, + { "target": "ipfs/go-ipfs-pinner" }, + { "target": "ipfs/go-ipfs-posinfo" }, + { "target": "ipfs/go-ipfs-pq" }, + { "target": "ipfs/go-ipfs-provider" }, + { "target": "ipfs/go-ipfs-routing" }, + { "target": "ipfs/go-ipfs-util" }, + { "target": "ipfs/go-ipld-cbor" }, + { "target": "ipfs/go-ipld-format" }, + { "target": "ipfs/go-ipld-git" }, + { "target": "ipfs/go-ipld-legacy" }, + { "target": "ipfs/go-ipns" }, + { "target": "ipfs/go-log" }, + { "target": "ipfs/go-merkledag" }, + { "target": "ipfs/go-metrics-interface" }, + { "target": "ipfs/go-metrics-prometheus" }, + { "target": "ipfs/go-mfs" }, + { "target": "ipfs/go-namesys" }, + { "target": "ipfs/go-path" }, + { "target": "ipfs/go-peertaskqueue" }, + { "target": "ipfs/go-qringbuf" }, + { "target": "ipfs/go-todocounter" }, + { "target": "ipfs/go-unixfs" }, + { "target": "ipfs/go-unixfsnode" }, + { "target": "ipfs/go-verifcid" }, + { "target": "ipfs/hang-fds" }, + { "target": "ipfs/interface-go-ipfs-core" }, + { "target": "ipfs/ipfs-ds-convert" }, + { "target": "ipfs/ipfs-update" }, + { "target": "ipfs/ipget" }, + { "target": "ipfs/iptb" }, + { "target": "ipfs/iptb-plugins" }, + { "target": "ipfs/pinbot-irc" }, + { "target": "ipfs/tar-utils" }, + { "target": "ipld/codec-fixtures" }, + { "target": "ipld/go-car" }, + { "target": "ipld/go-codec-dagpb" }, + { "target": "ipld/go-ipld-adl-hamt" }, + { "target": "ipld/go-ipld-btc" }, + { "target": "ipld/go-ipld-graphql" }, + { "target": "ipld/go-ipld-prime-proto" }, + { "target": "ipld/go-ipld-schema" }, + { "target": "ipld/go-ipld-selector-text-lite" }, + { "target": "ipld/go-ipldtool" }, + { "target": "ipld/go-storethehash" }, + { "target": "libp2p/dht-tracer1" }, + { "target": "libp2p/dht-utils" }, + { "target": "libp2p/go-addr-util" }, + { "target": "libp2p/go-buffer-pool" }, + { "target": "libp2p/go-cidranger" }, + { "target": "libp2p/go-composable-routing" }, + { "target": "libp2p/go-conn-security-multistream" }, + { "target": "libp2p/go-doh-resolver" }, + { "target": "libp2p/go-eventbus" }, + { "target": "libp2p/go-flow-metrics" }, + { "target": "libp2p/go-libp2p" }, + { "target": "libp2p/go-libp2p-asn-util" }, + { "target": "libp2p/go-libp2p-autonat" }, + { "target": "libp2p/go-libp2p-backoff" }, + { "target": "libp2p/go-libp2p-blankhost" }, + { "target": "libp2p/go-libp2p-circuit" }, + { "target": "libp2p/go-libp2p-connmgr" }, + { "target": "libp2p/go-libp2p-consensus" }, + { "target": "libp2p/go-libp2p-core" }, + { "target": "libp2p/go-libp2p-daemon" }, + { "target": "libp2p/go-libp2p-discovery" }, + { "target": "libp2p/go-libp2p-gorpc" }, + { "target": "libp2p/go-libp2p-gostream" }, + { "target": "libp2p/go-libp2p-http" }, + { "target": "libp2p/go-libp2p-introspector" }, + { "target": "libp2p/go-libp2p-kad-dht" }, + { "target": "libp2p/go-libp2p-kbucket" }, + { "target": "libp2p/go-libp2p-loggables" }, + { "target": "libp2p/go-libp2p-mplex" }, + { "target": "libp2p/go-libp2p-nat" }, + { "target": "libp2p/go-libp2p-netutil" }, + { "target": "libp2p/go-libp2p-noise" }, + { "target": "libp2p/go-libp2p-peerstore" }, + { "target": "libp2p/go-libp2p-pnet" }, + { "target": "libp2p/go-libp2p-pubsub-router" }, + { "target": "libp2p/go-libp2p-pubsub-tracer" }, + { "target": "libp2p/go-libp2p-quic-transport" }, + { "target": "libp2p/go-libp2p-raft" }, + { "target": "libp2p/go-libp2p-record" }, + { "target": "libp2p/go-libp2p-relay-daemon" }, + { "target": "libp2p/go-libp2p-routing-helpers" }, + { "target": "libp2p/go-libp2p-swarm" }, + { "target": "libp2p/go-libp2p-testing" }, + { "target": "libp2p/go-libp2p-tls" }, + { "target": "libp2p/go-libp2p-transport-upgrader" }, + { "target": "libp2p/go-libp2p-webrtc-direct" }, + { "target": "libp2p/go-libp2p-xor" }, + { "target": "libp2p/go-libp2p-yamux" }, + { "target": "libp2p/go-mplex" }, + { "target": "libp2p/go-msgio" }, + { "target": "libp2p/go-nat" }, + { "target": "libp2p/go-netroute" }, + { "target": "libp2p/go-openssl" }, + { "target": "libp2p/go-reuseport" }, + { "target": "libp2p/go-reuseport-transport" }, + { "target": "libp2p/go-routing-language" }, + { "target": "libp2p/go-smart-record" }, + { "target": "libp2p/go-sockaddr" }, + { "target": "libp2p/go-socket-activation" }, + { "target": "libp2p/go-stream-muxer-multistream" }, + { "target": "libp2p/go-tcp-transport" }, + { "target": "libp2p/go-ws-transport" }, + { "target": "libp2p/go-yamux" }, + { "target": "libp2p/hydra-booster" }, + { "target": "libp2p/repl" }, + { "target": "libp2p/zeroconf" }, + { "target": "multiformats/go-base32" }, + { "target": "multiformats/go-base36" }, + { "target": "multiformats/go-multiaddr" }, + { "target": "multiformats/go-multiaddr-dns" }, + { "target": "multiformats/go-multiaddr-fmt" }, + { "target": "multiformats/go-multibase" }, + { "target": "multiformats/go-multicodec" }, + { "target": "multiformats/go-multihash" }, + { "target": "multiformats/go-multistream" }, + { "target": "multiformats/go-varint" }, + { "target": "multiformats/ma-pipe" } + ] +} \ No newline at end of file diff --git a/configs/testing.json b/configs/testing.json index c438f770..9cc6c6a2 100644 --- a/configs/testing.json +++ b/configs/testing.json @@ -1,3 +1,5 @@ -[ - { "target": "protocol/.github-test-target" } -] +{ + "repositories": [ + { "target": "protocol/.github-test-target" } + ] +} From 67da4b220e59da09b4005162d8f7d5c192ad71a4 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 7 Dec 2021 15:42:30 +0100 Subject: [PATCH 05/24] make files part of the config --- .github/workflows/copy-workflow.yml | 11 +++++++---- .github/workflows/dispatch.yml | 10 ++++++---- configs/go.json | 11 +++++++++++ configs/testing.json | 3 +++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index 61cc9f12..6dd9c87a 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -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 @@ -158,7 +155,13 @@ jobs: - 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 + run: echo "FILES=${{ matrix.cfg.files }}" >> $GITHUB_ENV + - name: add more versioning workflows files, if necessary + if: matrix.cfg.deploy_versioning + run: | + files=$(jq -r '.[]' <<< '${{ env.FILES }}') + files+=(".github/workflows/releaser.yml" ".github/workflows/release-check.yml" ".github/workflows/tagpush.yml") + echo "FILES=$(jq -nc '$ARGS.positional' --args ${files[@]})" >> $GITHUB_ENV - name: Add files run: | for f in $(jq -r ".[]" <<< ${{ toJson(env.FILES) }}); do diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 2f99bc65..53f5b39b 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -12,7 +12,6 @@ env: # With ~180 repos, this means we'll run around 9 instances of the copy workflow in parallel. # This is (hopefully) sufficient to prevent us from triggering GitHub Action's abuse detection mechanism. MAX_REPOS_PER_WORKFLOW: 20 - FILES: '[ ".github/workflows/automerge.yml", ".github/workflows/go-test.yml", ".github/workflows/go-check.yml", ".github/workflows/releaser.yml", ".github/workflows/release-check.yml", ".github/workflows/tagpush.yml" ]' # a JSON array of the files to distribute jobs: matrix: @@ -28,7 +27,7 @@ jobs: if [[ $GITHUB_REF == refs/heads/testing ]]; then CONFIG=configs/testing.json fi - TARGETS=$(jq '.repositories | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})' $CONFIG | jq -sc '. | to_entries') + TARGETS=$(jq ".repositories[] | $(jq '.defaults' $CONFIG) + . | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})" $CONFIG | jq -sc '. | to_entries') echo "::set-output name=targets::$TARGETS" dispatch: needs: [ matrix ] @@ -40,7 +39,10 @@ jobs: # one per TARGETS "key" chunk above with a "value" array. # For each "dispatch" job, matrix.cfg.value is an array, like: # - # [{"target": "repo1"}, {"target": "repo2"}] + # [ + # {"target": "repo1", "files": [".github/workflows/go-check.yml"]}, + # {"target": "repo2", "files": [".github/workflows/go-check.yml", ".github/workflows/go-test.yml"]} + # ] # # The triggered copy-workflow jobs use that final array as their matrix. # As such, we'll end up with one copy-workflow parallel job per target. @@ -51,4 +53,4 @@ jobs: with: workflow: "Deploy" # "name" attribute of copy-workflow.yml token: ${{ secrets.WEB3BOT_GITHUB_TOKEN }} - inputs: '{ "head_commit_url": ${{ toJson(github.event.head_commit.url) }}, "files": ${{ toJson(env.FILES) }}, "targets": ${{ toJson(toJson(matrix.cfg.value)) }} }' + inputs: '{ "head_commit_url": ${{ toJson(github.event.head_commit.url) }}, "targets": ${{ toJson(toJson(matrix.cfg.value)) }} }' diff --git a/configs/go.json b/configs/go.json index 94f60a88..cf56d518 100644 --- a/configs/go.json +++ b/configs/go.json @@ -1,4 +1,15 @@ { + "defaults": { + "files": [ + ".github/workflows/automerge.yml", + ".github/workflows/go-test.yml", + ".github/workflows/go-check.yml", + ".github/workflows/releaser.yml", + ".github/workflows/release-check.yml", + ".github/workflows/tagpush.yml" + ], + "deploy_versioning": false + }, "repositories": [ { "target": "filecoin-project/go-amt-ipld" }, { "target": "filecoin-project/go-bitfield" }, diff --git a/configs/testing.json b/configs/testing.json index 9cc6c6a2..f1eaf8b6 100644 --- a/configs/testing.json +++ b/configs/testing.json @@ -1,4 +1,7 @@ { + "defaults": { + "files": [] + }, "repositories": [ { "target": "protocol/.github-test-target" } ] From b9aaa52210722ddb4ddef355a98db0af535aadd8 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 7 Dec 2021 16:16:22 +0100 Subject: [PATCH 06/24] move language specific copy-workflow setup to actions --- .github/actions/copy-workflow-go.yml | 63 +++++++++++ .github/actions/copy-workflow-versioning.yml | 22 ++++ .github/workflows/copy-workflow.yml | 113 ++++--------------- configs/go.json | 3 +- 4 files changed, 112 insertions(+), 89 deletions(-) create mode 100644 .github/actions/copy-workflow-go.yml create mode 100644 .github/actions/copy-workflow-versioning.yml diff --git a/.github/actions/copy-workflow-go.yml b/.github/actions/copy-workflow-go.yml new file mode 100644 index 00000000..4325b5a6 --- /dev/null +++ b/.github/actions/copy-workflow-go.yml @@ -0,0 +1,63 @@ +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/multiple-go-modules@v1.2 + 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/multiple-go-modules@v1.2 + 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 }} + run: | + gofmt -s -w . + if ! git diff --quiet; then + git add . + git commit -m "run gofmt -s" + fi diff --git a/.github/actions/copy-workflow-versioning.yml b/.github/actions/copy-workflow-versioning.yml new file mode 100644 index 00000000..9adad458 --- /dev/null +++ b/.github/actions/copy-workflow-versioning.yml @@ -0,0 +1,22 @@ +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 }} + 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: add more versioning workflows files + run: | + files=$(jq -r '.[]' <<< '${{ env.FILES }}') + files+=(".github/workflows/releaser.yml" ".github/workflows/release-check.yml" ".github/workflows/tagpush.yml") + echo "FILES=$(jq -nc '$ARGS.positional' --args ${files[@]})" >> $GITHUB_ENV diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index 6dd9c87a..eede2552 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -25,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" @@ -45,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: | @@ -60,108 +55,50 @@ 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: echo "FILES=${{ toJson(matrix.cfg.files) }}" >> $GITHUB_ENV + - name: is initial workflow deployment 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 }} + 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/multiple-go-modules@v1.2 - 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/multiple-go-modules@v1.2 - 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=${{ matrix.cfg.files }}" >> $GITHUB_ENV - - name: add more versioning workflows files, if necessary + - name: Run steps specific to go + if: matrix.cfg.deploy_go + uses: .github/actions/copy-workflow-go + - name: Run steps specific to versioning if: matrix.cfg.deploy_versioning - run: | - files=$(jq -r '.[]' <<< '${{ env.FILES }}') - files+=(".github/workflows/releaser.yml" ".github/workflows/release-check.yml" ".github/workflows/tagpush.yml") - echo "FILES=$(jq -nc '$ARGS.positional' --args ${files[@]})" >> $GITHUB_ENV + uses: .github/actions/copy-workflow-versioning - name: Add files run: | for f in $(jq -r ".[]" <<< ${{ toJson(env.FILES) }}); do diff --git a/configs/go.json b/configs/go.json index cf56d518..62eb74ca 100644 --- a/configs/go.json +++ b/configs/go.json @@ -8,7 +8,8 @@ ".github/workflows/release-check.yml", ".github/workflows/tagpush.yml" ], - "deploy_versioning": false + "deploy_versioning": false, + "deploy_go": true }, "repositories": [ { "target": "filecoin-project/go-amt-ipld" }, From 02436cf4f05f986097a99c2f055ab990b50ec5aa Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 7 Dec 2021 17:53:56 +0100 Subject: [PATCH 07/24] make dispatch workflow support more than one config json --- .github/workflows/dispatch.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 53f5b39b..7f37f066 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -23,11 +23,16 @@ jobs: - uses: actions/checkout@v2 - id: set-matrix run: | - CONFIG=configs/go.json - if [[ $GITHUB_REF == refs/heads/testing ]]; then - CONFIG=configs/testing.json - fi - TARGETS=$(jq ".repositories[] | $(jq '.defaults' $CONFIG) + . | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})" $CONFIG | jq -sc '. | to_entries') + TARGETS=() + for config in configs/*.json; do + if [[ $GITHUB_REF == refs/heads/testing && $config != configs/testing.json ]]; then + continue + fi + if [[ $GITHUB_REF != refs/heads/testing && $config == configs/testing.json ]]; then + continue + fi + TARGETS+=$(jq "[.repositories[] | $(jq '.defaults' $CONFIG) + .] | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})" $CONFIG | jq -sc '. | to_entries') + done echo "::set-output name=targets::$TARGETS" dispatch: needs: [ matrix ] @@ -44,6 +49,7 @@ jobs: # {"target": "repo2", "files": [".github/workflows/go-check.yml", ".github/workflows/go-test.yml"]} # ] # + # All array item in a batch are sourced from the same json config file. # The triggered copy-workflow jobs use that final array as their matrix. # As such, we'll end up with one copy-workflow parallel job per target. cfg: ${{ fromJson(needs.matrix.outputs.targets) }} From 0d71b9e2bb235ad285a88ac81255bb3a895ce677 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 7 Dec 2021 18:58:00 +0100 Subject: [PATCH 08/24] create fewer batches if possible --- .github/workflows/dispatch.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 7f37f066..412f1f32 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -18,7 +18,7 @@ jobs: name: Trigger copy workflows runs-on: ubuntu-latest outputs: - targets: ${{ steps.set-matrix.outputs.targets }} + batches: ${{ steps.set-matrix.outputs.batches }} steps: - uses: actions/checkout@v2 - id: set-matrix @@ -31,9 +31,10 @@ jobs: if [[ $GITHUB_REF != refs/heads/testing && $config == configs/testing.json ]]; then continue fi - TARGETS+=$(jq "[.repositories[] | $(jq '.defaults' $CONFIG) + .] | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})" $CONFIG | jq -sc '. | to_entries') + TARGETS+=($(jq -c ".repositories[] | $(jq '.defaults' $CONFIG) + ." $CONFIG)) done - echo "::set-output name=targets::$TARGETS" + BATCHES=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< $TARGETS) + echo "::set-output name=batches::$BATCHES" dispatch: needs: [ matrix ] runs-on: ubuntu-latest @@ -41,7 +42,7 @@ jobs: fail-fast: false matrix: # We end up with multiple "dispatch" jobs, - # one per TARGETS "key" chunk above with a "value" array. + # one per BATCHES "key" chunk above with a "value" array. # For each "dispatch" job, matrix.cfg.value is an array, like: # # [ @@ -49,14 +50,13 @@ jobs: # {"target": "repo2", "files": [".github/workflows/go-check.yml", ".github/workflows/go-test.yml"]} # ] # - # All array item in a batch are sourced from the same json config file. # The triggered copy-workflow jobs use that final array as their matrix. # As such, we'll end up with one copy-workflow parallel job per target. - cfg: ${{ fromJson(needs.matrix.outputs.targets) }} + cfg: ${{ fromJson(needs.matrix.outputs.batches) }} name: Start copy workflow (batch ${{ matrix.cfg.key }}) steps: - uses: benc-uk/workflow-dispatch@4c044c1613fabbe5250deadc65452d54c4ad4fc7 # v1.1.0 with: workflow: "Deploy" # "name" attribute of copy-workflow.yml token: ${{ secrets.WEB3BOT_GITHUB_TOKEN }} - inputs: '{ "head_commit_url": ${{ toJson(github.event.head_commit.url) }}, "targets": ${{ toJson(toJson(matrix.cfg.value)) }} }' + inputs: '{ "head_commit_url": ${{ toJson(github.event.head_commit.url) }}, "targets": ${{ toJson(matrix.cfg.value) }} }' From 082826785f57f329e795f502ef4330c53af1db26 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 10:01:26 +0100 Subject: [PATCH 09/24] set up copy-workflow actions properly --- .../actions/{copy-workflow-go.yml => copy-workflow-go/action.yml} | 0 .../action.yml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/actions/{copy-workflow-go.yml => copy-workflow-go/action.yml} (100%) rename .github/actions/{copy-workflow-versioning.yml => copy-workflow-versioning/action.yml} (100%) diff --git a/.github/actions/copy-workflow-go.yml b/.github/actions/copy-workflow-go/action.yml similarity index 100% rename from .github/actions/copy-workflow-go.yml rename to .github/actions/copy-workflow-go/action.yml diff --git a/.github/actions/copy-workflow-versioning.yml b/.github/actions/copy-workflow-versioning/action.yml similarity index 100% rename from .github/actions/copy-workflow-versioning.yml rename to .github/actions/copy-workflow-versioning/action.yml From 1dfeb94e5d8d416f9533b4bf75d357ec592bebd5 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 10:02:06 +0100 Subject: [PATCH 10/24] extract defaults from config separately --- .github/workflows/dispatch.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 412f1f32..082491a1 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -31,7 +31,8 @@ jobs: if [[ $GITHUB_REF != refs/heads/testing && $config == configs/testing.json ]]; then continue fi - TARGETS+=($(jq -c ".repositories[] | $(jq '.defaults' $CONFIG) + ." $CONFIG)) + DEFAULTS=$(jq -c '.defaults' $config) + TARGETS+=($(jq -c ".repositories[] | $DEFAULTS + ." $config)) done BATCHES=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< $TARGETS) echo "::set-output name=batches::$BATCHES" From 16e4ca83a09968e26c521453c129ddf4c2a973fa Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 10:25:07 +0100 Subject: [PATCH 11/24] bring back double toJson --- .github/workflows/dispatch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 082491a1..19d577ae 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -60,4 +60,4 @@ jobs: with: workflow: "Deploy" # "name" attribute of copy-workflow.yml token: ${{ secrets.WEB3BOT_GITHUB_TOKEN }} - inputs: '{ "head_commit_url": ${{ toJson(github.event.head_commit.url) }}, "targets": ${{ toJson(matrix.cfg.value) }} }' + inputs: '{ "head_commit_url": ${{ toJson(github.event.head_commit.url) }}, "targets": ${{ toJson(toJson(matrix.cfg.value)) }} }' From dbe2f9cbd2b063d31dfdac55f49d98f7d7e28686 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 10:38:47 +0100 Subject: [PATCH 12/24] use copy-workflow actions from same branch --- .github/workflows/copy-workflow.yml | 4 ++-- .github/workflows/dispatch.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index eede2552..e49d0c79 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -95,10 +95,10 @@ jobs: fi - name: Run steps specific to go if: matrix.cfg.deploy_go - uses: .github/actions/copy-workflow-go + uses: ./.github/actions/copy-workflow-go - name: Run steps specific to versioning if: matrix.cfg.deploy_versioning - uses: .github/actions/copy-workflow-versioning + uses: ./.github/actions/copy-workflow-versioning - name: Add files run: | for f in $(jq -r ".[]" <<< ${{ toJson(env.FILES) }}); do diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 19d577ae..7160c502 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -60,4 +60,5 @@ jobs: with: workflow: "Deploy" # "name" attribute of copy-workflow.yml token: ${{ secrets.WEB3BOT_GITHUB_TOKEN }} + # double toJson on matrix.cfg.value is here on purpose inputs: '{ "head_commit_url": ${{ toJson(github.event.head_commit.url) }}, "targets": ${{ toJson(toJson(matrix.cfg.value)) }} }' From f5cf5ab71014758969fab3e41b48f41b4c7bbb48 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 10:54:25 +0100 Subject: [PATCH 13/24] use compact json representation for storing FILES --- .github/workflows/copy-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index e49d0c79..f10afc67 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -58,7 +58,7 @@ jobs: - 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(matrix.cfg.files) }}" >> $GITHUB_ENV + run: echo "FILES=$(jq -c '.' <<< ${{ toJson(matrix.cfg.files) }})" >> $GITHUB_ENV - name: is initial workflow deployment run: | INITIAL_WORKFLOW_DEPLOYMENT=1 From 6955318314b123340c4f103d9ca9a9343fc746d1 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 11:00:26 +0100 Subject: [PATCH 14/24] fix files and local actions --- .github/actions/copy-workflow-versioning/action.yml | 2 +- .github/workflows/copy-workflow.yml | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/actions/copy-workflow-versioning/action.yml b/.github/actions/copy-workflow-versioning/action.yml index 9adad458..89d9a5eb 100644 --- a/.github/actions/copy-workflow-versioning/action.yml +++ b/.github/actions/copy-workflow-versioning/action.yml @@ -17,6 +17,6 @@ runs: fi - name: add more versioning workflows files run: | - files=$(jq -r '.[]' <<< '${{ env.FILES }}') + files=($(jq -r '.[]' <<< $FILES)) files+=(".github/workflows/releaser.yml" ".github/workflows/release-check.yml" ".github/workflows/tagpush.yml") echo "FILES=$(jq -nc '$ARGS.positional' --args ${files[@]})" >> $GITHUB_ENV diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index f10afc67..f4242585 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -58,11 +58,14 @@ jobs: - 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=$(jq -c '.' <<< ${{ toJson(matrix.cfg.files) }})" >> $GITHUB_ENV + run: | + files=${{ toJson(toJson(matrix.cfg.files)) }} + files=$(echo -e "$files" | jq -c '.') + echo "FILES=$files" >> $GITHUB_ENV - name: is initial workflow deployment run: | INITIAL_WORKFLOW_DEPLOYMENT=1 - for f in $(jq -r ".[]" <<< ${{ toJson(env.FILES) }}); do + for f in $(jq -r '.[]' <<< $FILES); do if [[ -f $TARGET_REPO_DIR/$f ]]; then INITIAL_WORKFLOW_DEPLOYMENT=0 break @@ -95,13 +98,13 @@ jobs: fi - name: Run steps specific to go if: matrix.cfg.deploy_go - uses: ./.github/actions/copy-workflow-go + uses: ./actions/copy-workflow-go - name: Run steps specific to versioning if: matrix.cfg.deploy_versioning - uses: ./.github/actions/copy-workflow-versioning + uses: ./actions/copy-workflow-versioning - name: Add files run: | - for f in $(jq -r ".[]" <<< ${{ toJson(env.FILES) }}); do + for f in $(jq -r '.[]' <<< $FILES); do echo -e "\nProcessing $f." # add DO NOT EDIT header tmp=$(mktemp) From c95cbfff04619c4ef48812014995ed9d62be7836 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 11:56:46 +0100 Subject: [PATCH 15/24] run actions from template repo --- .github/workflows/copy-workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index f4242585..b12cef24 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -98,10 +98,10 @@ jobs: fi - name: Run steps specific to go if: matrix.cfg.deploy_go - uses: ./actions/copy-workflow-go + uses: ./template-repo/.github/actions/copy-workflow-go - name: Run steps specific to versioning if: matrix.cfg.deploy_versioning - uses: ./actions/copy-workflow-versioning + uses: ./template-repo/.github/actions/copy-workflow-versioning - name: Add files run: | for f in $(jq -r '.[]' <<< $FILES); do From 5c86ae02e158d914b7f701a3965993c3fdb0f281 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 12:07:35 +0100 Subject: [PATCH 16/24] add missing shell property to actions --- .github/actions/copy-workflow-go/action.yml | 1 + .github/actions/copy-workflow-versioning/action.yml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/actions/copy-workflow-go/action.yml b/.github/actions/copy-workflow-go/action.yml index 4325b5a6..cb27a595 100644 --- a/.github/actions/copy-workflow-go/action.yml +++ b/.github/actions/copy-workflow-go/action.yml @@ -55,6 +55,7 @@ runs: - 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 diff --git a/.github/actions/copy-workflow-versioning/action.yml b/.github/actions/copy-workflow-versioning/action.yml index 89d9a5eb..67d10f0e 100644 --- a/.github/actions/copy-workflow-versioning/action.yml +++ b/.github/actions/copy-workflow-versioning/action.yml @@ -7,6 +7,7 @@ runs: - 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 @@ -16,6 +17,7 @@ runs: git commit -m "add version.json file" fi - name: add more versioning workflows files + shell: bash run: | files=($(jq -r '.[]' <<< $FILES)) files+=(".github/workflows/releaser.yml" ".github/workflows/release-check.yml" ".github/workflows/tagpush.yml") From 0b3c5cbb80c7204acf34dcd0b92f166b352c5643 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 8 Dec 2021 13:31:57 +0100 Subject: [PATCH 17/24] add configs README --- configs/README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 configs/README.md diff --git a/configs/README.md b/configs/README.md new file mode 100644 index 00000000..4d52aed6 --- /dev/null +++ b/configs/README.md @@ -0,0 +1,35 @@ +# Workflow Dispatch Configs + +This directory contains config files used for workflow dispatch. + +| name | description | +| --- | --- | +| go | repositories containing Go code | +| testing | repositories used for testing unified CI workflows | + +## Adding new repository to existing config file + +To add a new repository to an existing config file, add a new JSON object to the `repositories` key in the file. + +_**IMPORTANT**: Please remember to keep `repositories` sorted alphabetically by `target` value._ + +*JSON object example:* +``` +{ "target": "NEW REPOSITORY NAME" } +``` + +After the PR with your change is merged, a copy workflow that runs in this repository will copy files(as defined by the `defaults.files` key of the config file or an overriden `files` key of your newly added object) to your repository. + +## Adding new config file + +When adding a new JSON config file, please follow the structure of other config files. In particular, `defaults.files` array and `repositories` array are required fields. + +*JSON config file example:* +``` +{ + "defaults": { "files": [] }, + "repositories": [] +} +``` + +To customise the copy workflow further, you can add more fields to the `defaults` object. See `deploy_versioning` or `deploy_go` in [go.json](go.json#L8-L9) and how they are used in [copy-workflow.yml](../.github/workflows/copy-workflow.yml#L100-L105) for example. From 07f920283d60e3e3e44d341b634e903df085e8f8 Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 15 Dec 2021 13:17:54 +0100 Subject: [PATCH 18/24] set deploy_versioning=true for go repositories --- .github/actions/copy-workflow-versioning/action.yml | 6 ------ configs/go.json | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/actions/copy-workflow-versioning/action.yml b/.github/actions/copy-workflow-versioning/action.yml index 67d10f0e..6acf1714 100644 --- a/.github/actions/copy-workflow-versioning/action.yml +++ b/.github/actions/copy-workflow-versioning/action.yml @@ -16,9 +16,3 @@ runs: git add version.json git commit -m "add version.json file" fi - - name: add more versioning workflows files - shell: bash - run: | - files=($(jq -r '.[]' <<< $FILES)) - files+=(".github/workflows/releaser.yml" ".github/workflows/release-check.yml" ".github/workflows/tagpush.yml") - echo "FILES=$(jq -nc '$ARGS.positional' --args ${files[@]})" >> $GITHUB_ENV diff --git a/configs/go.json b/configs/go.json index 62eb74ca..19694277 100644 --- a/configs/go.json +++ b/configs/go.json @@ -8,7 +8,7 @@ ".github/workflows/release-check.yml", ".github/workflows/tagpush.yml" ], - "deploy_versioning": false, + "deploy_versioning": true, "deploy_go": true }, "repositories": [ From 9fdc4ebb836df059d3095d45fcb787b68a15d05d Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 15 Dec 2021 16:16:58 +0100 Subject: [PATCH 19/24] address review comments --- .githooks/pre-commit | 3 +-- .github/workflows/check-config.sh | 3 ++- .github/workflows/check-config.yml | 4 +++- .github/workflows/copy-workflow.yml | 13 +++++++------ .github/workflows/dispatch.yml | 14 +++++++++----- .github/workflows/stale-repos.yml | 2 ++ configs/README.md | 6 +++--- configs/go.json | 2 +- 8 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 796b8fe9..64b4af90 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -4,8 +4,7 @@ for config in configs/*.json; do tmp=$(mktemp) git show :$config > $tmp status=0 - if ! output=$(.github/workflows/check-config.sh $tmp); then - echo "$tmp contains git show :$config output." + if ! output=$(.github/workflows/check-config.sh $tmp $config); then echo "$output" status=1 fi diff --git a/.github/workflows/check-config.sh b/.github/workflows/check-config.sh index 53887d41..c05ace2b 100755 --- a/.github/workflows/check-config.sh +++ b/.github/workflows/check-config.sh @@ -3,6 +3,7 @@ set -e file=$1 +source=${2:-$file} entries=$(mktemp) entries_sorted=$(mktemp) @@ -10,7 +11,7 @@ jq -r ".repositories[].target" $file > $entries sort -u $entries > $entries_sorted status=0 if ! output=$(diff -y $entries $entries_sorted); then - echo "Targets in $file not sorted alphabetically:" + echo "Targets in $source not sorted alphabetically:" echo "$output" status=1 fi diff --git a/.github/workflows/check-config.yml b/.github/workflows/check-config.yml index 918c58d8..5b3af314 100644 --- a/.github/workflows/check-config.yml +++ b/.github/workflows/check-config.yml @@ -12,8 +12,10 @@ jobs: targets: ${{ steps.set-matrix.outputs.targets }} steps: - uses: actions/checkout@v2 - - name: check if configs/*.json is sorted alphabetically + - 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 diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index b12cef24..9cc29f75 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -63,15 +63,16 @@ jobs: 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 + initial_workflow_deployment=1 for f in $(jq -r '.[]' <<< $FILES); do if [[ -f $TARGET_REPO_DIR/$f ]]; then - INITIAL_WORKFLOW_DEPLOYMENT=0 + initial_workflow_deployment=0 break fi done - echo "INITIAL_WORKFLOW_DEPLOYMENT=$INITIAL_WORKFLOW_DEPLOYMENT" >> $GITHUB_ENV + 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 }} @@ -98,13 +99,13 @@ jobs: fi - name: Run steps specific to go if: matrix.cfg.deploy_go - uses: ./template-repo/.github/actions/copy-workflow-go + uses: ./${{ env.TEMPATE_REPO_DIR }}/.github/actions/copy-workflow-go - name: Run steps specific to versioning if: matrix.cfg.deploy_versioning - uses: ./template-repo/.github/actions/copy-workflow-versioning + uses: ./${{ env.TEMPATE_REPO_DIR }}/.github/actions/copy-workflow-versioning - name: Add files run: | - for f in $(jq -r '.[]' <<< $FILES); do + for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do echo -e "\nProcessing $f." # add DO NOT EDIT header tmp=$(mktemp) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 7160c502..63ffc3e5 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -23,19 +23,23 @@ jobs: - uses: actions/checkout@v2 - id: set-matrix run: | - TARGETS=() + targets=() for config in configs/*.json; do + echo "::group::$config" if [[ $GITHUB_REF == refs/heads/testing && $config != configs/testing.json ]]; then continue fi if [[ $GITHUB_REF != refs/heads/testing && $config == configs/testing.json ]]; then continue fi - DEFAULTS=$(jq -c '.defaults' $config) - TARGETS+=($(jq -c ".repositories[] | $DEFAULTS + ." $config)) + defaults=$(jq -c '.defaults' $config) + # values defined in the repository object will override the default values + # e.g. { "files": ["a", "b"] } + { "files": ["c"] } = { "files": ["c"] } + targets+=($(jq -c ".repositories[] | $defaults + ." $config)) + echo "::endgroup::" done - BATCHES=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< $TARGETS) - echo "::set-output name=batches::$BATCHES" + batches=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< $targets) + echo "::set-output name=batches::$batches" dispatch: needs: [ matrix ] runs-on: ubuntu-latest diff --git a/.github/workflows/stale-repos.yml b/.github/workflows/stale-repos.yml index 89baa9fe..c70a42df 100644 --- a/.github/workflows/stale-repos.yml +++ b/.github/workflows/stale-repos.yml @@ -12,6 +12,7 @@ jobs: run: | status=0 for config in configs/*.json; do + echo "::group::$config" for repo in $(jq -r '.repositories[].target' $config); do exists=true output=$(curl -s -f -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$repo") || exists=false @@ -25,5 +26,6 @@ jobs: status=1 fi done + echo "::endgroup::" done exit $status diff --git a/configs/README.md b/configs/README.md index 4d52aed6..4ab27dd1 100644 --- a/configs/README.md +++ b/configs/README.md @@ -14,7 +14,7 @@ To add a new repository to an existing config file, add a new JSON object to the _**IMPORTANT**: Please remember to keep `repositories` sorted alphabetically by `target` value._ *JSON object example:* -``` +```json { "target": "NEW REPOSITORY NAME" } ``` @@ -25,11 +25,11 @@ After the PR with your change is merged, a copy workflow that runs in this repos When adding a new JSON config file, please follow the structure of other config files. In particular, `defaults.files` array and `repositories` array are required fields. *JSON config file example:* -``` +```json { "defaults": { "files": [] }, "repositories": [] } ``` -To customise the copy workflow further, you can add more fields to the `defaults` object. See `deploy_versioning` or `deploy_go` in [go.json](go.json#L8-L9) and how they are used in [copy-workflow.yml](../.github/workflows/copy-workflow.yml#L100-L105) for example. +To customise the copy workflow further, you can add more fields to the `defaults` object. See `deploy_versioning` or `deploy_go` in [go.json](go.json) and how they are used in [copy-workflow.yml](../.github/workflows/copy-workflow.yml) for example. diff --git a/configs/go.json b/configs/go.json index 19694277..c6dce5e3 100644 --- a/configs/go.json +++ b/configs/go.json @@ -189,4 +189,4 @@ { "target": "multiformats/go-varint" }, { "target": "multiformats/ma-pipe" } ] -} \ No newline at end of file +} From 60d1f292b18587aef00eb7f0c535af888258998d Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 15 Dec 2021 16:21:52 +0100 Subject: [PATCH 20/24] restore hardcoded template-repo reference --- .github/workflows/copy-workflow.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index 9cc29f75..80287fc9 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -99,10 +99,11 @@ jobs: fi - name: Run steps specific to go if: matrix.cfg.deploy_go - uses: ./${{ env.TEMPATE_REPO_DIR }}/.github/actions/copy-workflow-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: ./${{ env.TEMPATE_REPO_DIR }}/.github/actions/copy-workflow-versioning + uses: ./template-repo/.github/actions/copy-workflow-versioning - name: Add files run: | for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do From a71f87a0d506dfde49763755e91f1eb8732828cb Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 15 Dec 2021 16:40:32 +0100 Subject: [PATCH 21/24] add section on config testing --- configs/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/configs/README.md b/configs/README.md index 4ab27dd1..9d51d514 100644 --- a/configs/README.md +++ b/configs/README.md @@ -33,3 +33,7 @@ When adding a new JSON config file, please follow the structure of other config ``` To customise the copy workflow further, you can add more fields to the `defaults` object. See `deploy_versioning` or `deploy_go` in [go.json](go.json) and how they are used in [copy-workflow.yml](../.github/workflows/copy-workflow.yml) for example. + +## Testing + +You can use [testing](https://github.com/protocol/.github/tree/testing) branch for worklow/configuration testing. Once you push your changes to the branch, a [dispatch](../.github/workflows/dispatch.yml) workflow will be triggered. The workflow will use [testing.json](testing.json) configuration file only. You can manipalate that configuration file as needed(you can copy all the `defaults` from [go.json](go.json) for [example](https://github.com/protocol/.github/commit/43476995428996a90ca95bf838f084ba1a710c68)). From 0f3408041c3d962dd18cfdeba950718a1eb123c2 Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 16 Dec 2021 13:00:12 +0100 Subject: [PATCH 22/24] fix batches creation --- .github/workflows/copy-workflow.yml | 2 +- .github/workflows/dispatch.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index 80287fc9..0713300e 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -66,7 +66,7 @@ jobs: # 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 '.[]' <<< $FILES); do + for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do if [[ -f $TARGET_REPO_DIR/$f ]]; then initial_workflow_deployment=0 break diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 63ffc3e5..8b2742c1 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -38,7 +38,7 @@ jobs: targets+=($(jq -c ".repositories[] | $defaults + ." $config)) echo "::endgroup::" done - batches=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< $targets) + batches=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< "${targets[@]") echo "::set-output name=batches::$batches" dispatch: needs: [ matrix ] From b2c1dd9869f74e8b9af0a7d8903bb7a74bcfc0fe Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 16 Dec 2021 18:58:11 +0100 Subject: [PATCH 23/24] fix command that produces batches --- .github/workflows/dispatch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 8b2742c1..59c0eba0 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -38,7 +38,7 @@ jobs: targets+=($(jq -c ".repositories[] | $defaults + ." $config)) echo "::endgroup::" done - batches=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< "${targets[@]") + batches=$(jq -sc '[. | _nwise(${{ env.MAX_REPOS_PER_WORKFLOW }})] | to_entries' <<< "${targets[@]}") echo "::set-output name=batches::$batches" dispatch: needs: [ matrix ] From 664f8b719a0e99545262c7ae7ccc73f6b0cb2d9b Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 16 Dec 2021 19:55:19 +0100 Subject: [PATCH 24/24] fix needs update logic --- .github/workflows/copy-workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index 0713300e..af0f407e 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -139,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 - 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 }}