From 526400f59297dbeddfed095d5ad662860b03817e Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 7 Dec 2021 13:24:35 +0100 Subject: [PATCH 01/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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 }} From d54c585fc29fd23911190926cb91d626e2771ea1 Mon Sep 17 00:00:00 2001 From: galargh Date: Fri, 17 Dec 2021 16:59:37 +0100 Subject: [PATCH 25/44] add template and reusable workflow for sync-release-assets --- .github/workflows/copy-workflow.yml | 4 +- .github/workflows/sync-release-assets.yml | 139 ++++++++++++++++++ configs/go.json | 30 +++- .../.github/workflows/sync-release-assets.yml | 11 ++ 4 files changed, 177 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/sync-release-assets.yml create mode 100644 templates/.github/workflows/sync-release-assets.yml diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index af0f407e..2a23fe9b 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -60,7 +60,8 @@ jobs: # 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: | files=${{ toJson(toJson(matrix.cfg.files)) }} - files=$(echo -e "$files" | jq -c '.') + extra_files=${{ toJson(toJson(matrix.cfg.extra_files)) }} + files=$(echo -e "$files" "$extra_files" | jq -nc '[inputs] | add') 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 @@ -113,6 +114,7 @@ jobs: cat $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/header.yml $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f > $tmp # replace $default-branch with this repo's GitHub default branch sed -i "s:\$default-branch:${{ env.DEFAULTBRANCH }}:g" $tmp + sed -i "s:\$config:${{ toJson(toJson(matrix.cfg)) }}:g" $tmp mv $tmp $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f # create commit, if necessary commit_msg="" diff --git a/.github/workflows/sync-release-assets.yml b/.github/workflows/sync-release-assets.yml new file mode 100644 index 00000000..53b6590f --- /dev/null +++ b/.github/workflows/sync-release-assets.yml @@ -0,0 +1,139 @@ +name: Sync github release assets with dist.ipfs.io +on: + workflow_call: + inputs: + dist: + required: true + type: string + +concurrency: + group: release-assets-dist-sync + cancel-in-progress: true + +jobs: + sync-github-and-dist-ipfs-io: + runs-on: "ubuntu-latest" + steps: + - uses: ipfs/download-ipfs-distribution-action@v1 + - uses: ipfs/start-ipfs-daemon-action@v1 + with: + args: --init --init-profile=flatfs,server --enable-gc=false + - uses: actions/setup-node@v2 + with: + node-version: 14 + - name: Sync the latest 5 github releases + uses: actions/github-script@v4 + with: + script: | + const fs = require('fs').promises + const max_synced = 5 + + // fetch github releases + resp = await github.repos.listReleases({ + owner: context.repo.owner, + repo: context.repo.repo, + page: 1, + per_page: max_synced + }) + const release_assets = []; + num_synced = 0; + for (const release of resp.data) { + console.log("checking release tagged", release.tag_name) + if (release.draft || release.prerelease) { + console.log("skipping draft/prerelease tagged", release.tag_name) + continue + } + if (num_synced > max_synced) { + console.log("done: synced", max_synced, "latest releases") + break; + } + num_synced += 1 + + const github_assets = new Set() + for (const asset of release.assets) { + github_assets.add(asset.name) + } + + // fetch asset info from dist.ipfs.io + p = '/ipns/dist.ipfs.io/${{ inputs.di }}/' + release.tag_name + let stdout = '' + const options = {} + options.listeners = { + stdout: (data) => { + stdout += data.toString(); + } + } + await exec.exec('ipfs', ['ls', p], options) + + const dist_assets = new Set() + const missing_files = [] + for (const raw_line of stdout.split("\n")) { + line = raw_line.trim(); + if (line.length != 0) { + file = line.split(/(\s+)/).filter( function(e) { return e.trim().length > 0; } )[2] + dist_assets.add(file) + if (!github_assets.has(file)) { + missing_files.push(file) + } + } + } + + // if dist.ipfs.io has files not found in github, copy them over + for (const file of missing_files) { + file_sha = file + ".sha512" + file_cid = file + ".cid" + + // skip files that don't have .cid and .sha512 checksum files + if (!dist_assets.has(file_sha) || !dist_assets.has(file_cid)) { + if (!file.endsWith('.cid') && !file.endsWith('.sha512')) { // silent skip of .sha512.sha512 :) + console.log(`skipping "${file}" as dist.ipfs.io does not provide .cid and .sha512 checksum files for it`) + } + continue + } + + console.log("fetching", file, "from dist.ipfs.io") + await exec.exec('ipfs', ['get', p + '/' + file]) + await exec.exec('ipfs', ['get', p + '/' + file_sha]) + await exec.exec('ipfs', ['get', p + '/' + file_cid]) + console.log("verifying contents of", file) + + // compute sha512 output for file + let sha_stdout = '' + const sha_options = {} + sha_options.listeners = { + stdout: (data) => { + sha_stdout += data.toString(); + } + } + await exec.exec('sha512sum', [file], sha_options) + // read expected sha512 output + const sha_data = await fs.readFile(file_sha, "utf8") + const digest = (s) => s.split(' ').shift() + if (digest(sha_data) != digest(sha_stdout)) { + console.log(`${file}.sha512: ${sha_data}`) + console.log(`sha512sum ${file}: ${sha_stdout}`) + throw "checksum verification failed for " + file + } + + console.log("uploading", file, "to github release", release.tag_name) + const uploadReleaseAsset = async (file) => github.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.id, + headers: { + "content-type": "application/octet-stream", + "content-length": `${(await fs.stat(file)).size}` + }, + name: file, + data: await fs.readFile(file) + }) + await uploadReleaseAsset(file) + await uploadReleaseAsset(file_sha) + await uploadReleaseAsset(file_cid) + + } + // summary of assets on both sides + release_assets.push({ tag: release.tag_name, github_assets, dist_assets }) + } + console.log(release_assets) + return release_assets diff --git a/configs/go.json b/configs/go.json index c6dce5e3..aedadab7 100644 --- a/configs/go.json +++ b/configs/go.json @@ -1,11 +1,11 @@ { "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/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": true, @@ -53,6 +53,16 @@ { "target": "ipfs/go-filestore" }, { "target": "ipfs/go-fs-lock" }, { "target": "ipfs/go-graphsync" }, + { + "target": "ipfs/go-ipfs", + "files": [ + ".github/workflows/automerge.yml", + ".github/workflows/sync-release-assets.yml" + ], + "sync_release_assets": { + "dist": "go-ipfs" + } + }, { "target": "ipfs/go-ipfs-api" }, { "target": "ipfs/go-ipfs-blockstore" }, { "target": "ipfs/go-ipfs-blocksutil" }, @@ -150,7 +160,15 @@ { "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-relay-daemon", + "extra_files": [ + ".github/workflows/sync-release-assets.yml" + ], + "sync_release_assets": { + "dist": "libp2p-relay-daemon" + } + }, { "target": "libp2p/go-libp2p-routing-helpers" }, { "target": "libp2p/go-libp2p-swarm" }, { "target": "libp2p/go-libp2p-testing" }, diff --git a/templates/.github/workflows/sync-release-assets.yml b/templates/.github/workflows/sync-release-assets.yml new file mode 100644 index 00000000..5b29cd11 --- /dev/null +++ b/templates/.github/workflows/sync-release-assets.yml @@ -0,0 +1,11 @@ +name: Sync github release assets with dist.ipfs.io +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * *' + +jobs: + sync-github-and-dist-ipfs-io: + uses: protocol/.github/.github/workflows/sync-release-assets.yml@master + with: + dist: ${{ fromJson('$config').sync_release_assets.dist }} From 756a68cffb7e636e561dde38960fc485caf7c5a2 Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 20 Dec 2021 10:37:31 +0100 Subject: [PATCH 26/44] do not include the entire config in copied file --- .github/workflows/copy-workflow.yml | 16 ++++++++++------ .../.github/workflows/sync-release-assets.yml | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index 2a23fe9b..8a21f725 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -30,7 +30,7 @@ jobs: FILES: "" GITHUB_USER: "web3-bot" GITHUB_EMAIL: "web3-bot@users.noreply.github.com" - DEFAULTBRANCH: "" + DEFAULT_BRANCH: "" name: ${{ matrix.cfg.target }} steps: - name: Checkout ${{ matrix.cfg.target }} @@ -48,8 +48,8 @@ jobs: - name: determine GitHub default branch working-directory: ${{ env.TARGET_REPO_DIR }} run: | - defaultbranch=$(git remote show origin | awk '/HEAD branch/ {print $NF}') - echo "DEFAULTBRANCH=$defaultbranch" >> $GITHUB_ENV + default_branch=$(git remote show origin | awk '/HEAD branch/ {print $NF}') + echo "DEFAULT_BRANCH=$default_branch" >> $GITHUB_ENV - name: git config working-directory: ${{ env.TARGET_REPO_DIR }} run: | @@ -107,14 +107,18 @@ jobs: uses: ./template-repo/.github/actions/copy-workflow-versioning - name: Add files run: | + config="$(echo -e '${{ toJson(toJson(matrix.cfg)) }}' | jq -c '.')" + github="{\"repo\":{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}}" + context="{\"config\":\"$config\",\"github\":\"$github\"}" + regexp='\${{{\s*(.*?)\s*}}}' + replacement="qx/context='$context'; jq -jc '.\$1' <<< \"\\\$context\"/" for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do echo -e "\nProcessing $f." # add DO NOT EDIT header tmp=$(mktemp) cat $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/header.yml $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f > $tmp - # replace $default-branch with this repo's GitHub default branch - sed -i "s:\$default-branch:${{ env.DEFAULTBRANCH }}:g" $tmp - sed -i "s:\$config:${{ toJson(toJson(matrix.cfg)) }}:g" $tmp + # replace ${{{ SELECTOR }}} with a value from the JSON context object + perl -pi -e "s#$regex#$replacement#ge" $tmp mv $tmp $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f # create commit, if necessary commit_msg="" diff --git a/templates/.github/workflows/sync-release-assets.yml b/templates/.github/workflows/sync-release-assets.yml index 5b29cd11..ce2dba12 100644 --- a/templates/.github/workflows/sync-release-assets.yml +++ b/templates/.github/workflows/sync-release-assets.yml @@ -8,4 +8,4 @@ jobs: sync-github-and-dist-ipfs-io: uses: protocol/.github/.github/workflows/sync-release-assets.yml@master with: - dist: ${{ fromJson('$config').sync_release_assets.dist }} + dist: ${{{ config.sync_release_assets.dist }}} From 557dd059131a46276f9aa18c17ce6d3f09471496 Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 20 Dec 2021 12:43:22 +0100 Subject: [PATCH 27/44] escape { in regexp pattern so that Actions don't interpret it --- .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 8a21f725..1063d4ef 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -110,14 +110,14 @@ jobs: config="$(echo -e '${{ toJson(toJson(matrix.cfg)) }}' | jq -c '.')" github="{\"repo\":{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}}" context="{\"config\":\"$config\",\"github\":\"$github\"}" - regexp='\${{{\s*(.*?)\s*}}}' + regexp='\$\{\{\{\s*(.*?)\s*\}\}\}' replacement="qx/context='$context'; jq -jc '.\$1' <<< \"\\\$context\"/" for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do echo -e "\nProcessing $f." # add DO NOT EDIT header tmp=$(mktemp) cat $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/header.yml $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f > $tmp - # replace ${{{ SELECTOR }}} with a value from the JSON context object + # replace template expressions with values from the JSON context object perl -pi -e "s#$regex#$replacement#ge" $tmp mv $tmp $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f # create commit, if necessary From 95fc5c8132a8595a258f9d6978899f42e4ce0110 Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 20 Dec 2021 12:51:32 +0100 Subject: [PATCH 28/44] fix context variable setup --- .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 1063d4ef..7cd7f6e4 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -107,9 +107,10 @@ jobs: uses: ./template-repo/.github/actions/copy-workflow-versioning - name: Add files run: | - config="$(echo -e '${{ toJson(toJson(matrix.cfg)) }}' | jq -c '.')" + config=${{ toJson(toJson(matrix.cfg)) }} + config=$(echo -e "$config" | jq -c '.') github="{\"repo\":{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}}" - context="{\"config\":\"$config\",\"github\":\"$github\"}" + context="{\"config\":$config,\"github\":$github}" regexp='\$\{\{\{\s*(.*?)\s*\}\}\}' replacement="qx/context='$context'; jq -jc '.\$1' <<< \"\\\$context\"/" for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do From 1dcd301c05c45a5ea66a4628fc9cbcf00a7375ed Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 20 Dec 2021 13:21:16 +0100 Subject: [PATCH 29/44] escape slashes --- .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 7cd7f6e4..28405cf9 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -112,14 +112,14 @@ jobs: github="{\"repo\":{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}}" context="{\"config\":$config,\"github\":$github}" regexp='\$\{\{\{\s*(.*?)\s*\}\}\}' - replacement="qx/context='$context'; jq -jc '.\$1' <<< \"\\\$context\"/" + replacement="qx/context='${context//\//\\\/}'; jq -jc '.\$1' <<< \"\\\$context\"/" for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do echo -e "\nProcessing $f." # add DO NOT EDIT header tmp=$(mktemp) cat $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/header.yml $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f > $tmp # replace template expressions with values from the JSON context object - perl -pi -e "s#$regex#$replacement#ge" $tmp + perl -pi -e "s#$regexp#$replacement#ge" $tmp mv $tmp $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f # create commit, if necessary commit_msg="" From 6d142559e207c90d9b7d73b083a396941da4ba7f Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 20 Dec 2021 15:20:50 +0100 Subject: [PATCH 30/44] echo context instead of input redirect --- .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 28405cf9..51681090 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -112,7 +112,7 @@ jobs: github="{\"repo\":{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}}" context="{\"config\":$config,\"github\":$github}" regexp='\$\{\{\{\s*(.*?)\s*\}\}\}' - replacement="qx/context='${context//\//\\\/}'; jq -jc '.\$1' <<< \"\\\$context\"/" + replacement="qx/echo '${context//\//\\\/}' | jq -jc '.\$1'/" for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do echo -e "\nProcessing $f." # add DO NOT EDIT header From 8696afd7f90659d5c1114c56d24dff1f3df3bbac Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 21 Dec 2021 11:42:18 +0100 Subject: [PATCH 31/44] use backticks instead of qx syntax --- .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 51681090..85802bfa 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -112,7 +112,7 @@ jobs: github="{\"repo\":{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}}" context="{\"config\":$config,\"github\":$github}" regexp='\$\{\{\{\s*(.*?)\s*\}\}\}' - replacement="qx/echo '${context//\//\\\/}' | jq -jc '.\$1'/" + replacement="\`echo '$context' | jq -jc '.\$1'\`" for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do echo -e "\nProcessing $f." # add DO NOT EDIT header From b7087088b1cad0c1d1fe958f22357193b5f3a60f Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 21 Dec 2021 12:21:12 +0100 Subject: [PATCH 32/44] remove repo object from github context --- .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 85802bfa..0d4dea15 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -109,7 +109,7 @@ jobs: run: | config=${{ toJson(toJson(matrix.cfg)) }} config=$(echo -e "$config" | jq -c '.') - github="{\"repo\":{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}}" + github="{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}" context="{\"config\":$config,\"github\":$github}" regexp='\$\{\{\{\s*(.*?)\s*\}\}\}' replacement="\`echo '$context' | jq -jc '.\$1'\`" From ba2b680ea91b64d0ae667b6650a7277875412bb9 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 21 Dec 2021 12:29:12 +0100 Subject: [PATCH 33/44] add templates README --- templates/README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 templates/README.md diff --git a/templates/README.md b/templates/README.md new file mode 100644 index 00000000..00b7e5ab --- /dev/null +++ b/templates/README.md @@ -0,0 +1,76 @@ +# Templates + +This directory contains template files that can be expanded and copied over to the configured repositories. + +## Contexts + +You can access context information during template expansion(before copy is performed). + +### About contexts + +Contexts are a way to access information about the repository configuration object and repository GitHub settings. Contexts use the following syntax: + +``` +${{{ }}} +``` + +| Context name | Type | Description | +| --- | --- | --- | +| `config` | `object` | Configuration object because of which the file is being copied. For more information, see [config context](#config-context) | +| `github` | `object` | Information about the target repository the file is being copied to. For more information, see [github context](#github-context) | + +#### `config` context + +The `config` context is the configuration object because of which the file is being copied. + +| Property name | Type | Description | +| --- | --- | --- | +| `config` | `object` | The top-level context. | +| `config.files` | `array` | The files that are being copied. | +| `config.extra_files` | `object` | The additional files that are also being copied. | +| `config.target` | `string` | The name of the target repository in `{owner}/{repo}` format. | + +#### `github` context + +The `github` context contains information about the target repository the file is being copied to. + +| Property name | Type | Description | +| --- | --- | --- | +| `github` | `object` | The top-level context. | +| `github.default_branch` | `string` | The name of the default branch of the target repository. | + +### Examples + +#### Context container + +```json +{ + "config": { + "example": { + "greeting": "Hello" + }, + "files": [], + "extra_files": [".github/workflows/example.yml"] + "target": "protocol/.github-test-target" + }, + "github": { + "default_branch": "master" + } +} +``` + +#### Template expanding context + +```yaml +name: Hello +on: + push: + branches: + - ${{{ github.default_branch }}} +jobs: + echo: + runs-on: ubuntu-latest + steps: + - run: echo ${{{ config.example.greeting }}} + shell: bash +``` From d44d8620049eb918683fa5328bb91a47b3a7fb3b Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 21 Dec 2021 12:31:16 +0100 Subject: [PATCH 34/44] fix inputs usage in sync-release-assets workflow --- .github/workflows/sync-release-assets.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-release-assets.yml b/.github/workflows/sync-release-assets.yml index 53b6590f..7de25d5e 100644 --- a/.github/workflows/sync-release-assets.yml +++ b/.github/workflows/sync-release-assets.yml @@ -55,7 +55,7 @@ jobs: } // fetch asset info from dist.ipfs.io - p = '/ipns/dist.ipfs.io/${{ inputs.di }}/' + release.tag_name + p = '/ipns/dist.ipfs.io/${{ inputs.dist }}/' + release.tag_name let stdout = '' const options = {} options.listeners = { From 359f6a54d31aa27b5014b0595c0346b856b6267c Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 21 Dec 2021 16:03:53 +0100 Subject: [PATCH 35/44] simplify dist config --- configs/go.json | 8 ++------ templates/.github/workflows/sync-release-assets.yml | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/configs/go.json b/configs/go.json index aedadab7..b31f3f52 100644 --- a/configs/go.json +++ b/configs/go.json @@ -59,9 +59,7 @@ ".github/workflows/automerge.yml", ".github/workflows/sync-release-assets.yml" ], - "sync_release_assets": { - "dist": "go-ipfs" - } + "dist": "go-ipfs" }, { "target": "ipfs/go-ipfs-api" }, { "target": "ipfs/go-ipfs-blockstore" }, @@ -165,9 +163,7 @@ "extra_files": [ ".github/workflows/sync-release-assets.yml" ], - "sync_release_assets": { - "dist": "libp2p-relay-daemon" - } + "dist": "libp2p-relay-daemon" }, { "target": "libp2p/go-libp2p-routing-helpers" }, { "target": "libp2p/go-libp2p-swarm" }, diff --git a/templates/.github/workflows/sync-release-assets.yml b/templates/.github/workflows/sync-release-assets.yml index ce2dba12..b1e0f621 100644 --- a/templates/.github/workflows/sync-release-assets.yml +++ b/templates/.github/workflows/sync-release-assets.yml @@ -8,4 +8,4 @@ jobs: sync-github-and-dist-ipfs-io: uses: protocol/.github/.github/workflows/sync-release-assets.yml@master with: - dist: ${{{ config.sync_release_assets.dist }}} + dist: ${{{ config.dist }}} From 1100c54b197c28f14bd44fcd40e60590e7f3ccd3 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 21 Dec 2021 16:07:38 +0100 Subject: [PATCH 36/44] add all fields that might appear in config context --- templates/README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/templates/README.md b/templates/README.md index 00b7e5ab..7d3feb11 100644 --- a/templates/README.md +++ b/templates/README.md @@ -23,21 +23,24 @@ ${{{ }}} The `config` context is the configuration object because of which the file is being copied. -| Property name | Type | Description | -| --- | --- | --- | -| `config` | `object` | The top-level context. | -| `config.files` | `array` | The files that are being copied. | -| `config.extra_files` | `object` | The additional files that are also being copied. | -| `config.target` | `string` | The name of the target repository in `{owner}/{repo}` format. | +| Property name | Type | Always present | Description | +| --- | --- | --- | --- | +| `config` | `object` | `true` | The top-level context. | true | +| `config.files` | `array` | `true` | The files that are being copied. | +| `config.extra_files` | `array` | `false` | The additional files that are also being copied. | +| `config.target` | `string` | `true` | The name of the target repository in `{owner}/{repo}` format. | +| `config.deploy_go` | `boolean` | `false` | Flag controling if Go specific setup should be applied to the repository. | +| `config.deploy_versioning` | `boolean` | `false` | Flag controling if `versions.json` file should be deployed to the repository. | +| `config.dist` | `string` | `false` | The name of the distribution built from the repository. | #### `github` context The `github` context contains information about the target repository the file is being copied to. -| Property name | Type | Description | +| Property name | Type | Always present | Description | | --- | --- | --- | -| `github` | `object` | The top-level context. | -| `github.default_branch` | `string` | The name of the default branch of the target repository. | +| `github` | `object` | `true` | The top-level context. | +| `github.default_branch` | `string` | `true` | The name of the default branch of the target repository. | ### Examples From 9706e9c0c01ef6671af1dbbd981787c980d522b1 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 21 Dec 2021 16:08:00 +0100 Subject: [PATCH 37/44] escape single quotes when executing bash from perl --- .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 0d4dea15..ae8c8f5f 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -112,7 +112,7 @@ jobs: github="{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}" context="{\"config\":$config,\"github\":$github}" regexp='\$\{\{\{\s*(.*?)\s*\}\}\}' - replacement="\`echo '$context' | jq -jc '.\$1'\`" + replacement="\$filter = \".\$1\"; \$filter =~ s/'/'\"'\"'/g; \`echo '${context//\'/\'\"\'\"\'}' | jq -jc '\$filter'\`" for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do echo -e "\nProcessing $f." # add DO NOT EDIT header From 486f183d83a80dd1a48589b8bfbf1672f8167064 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 21 Dec 2021 16:16:53 +0100 Subject: [PATCH 38/44] add comments explaining the perl script --- .github/workflows/copy-workflow.yml | 8 +++++++- templates/README.md | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/copy-workflow.yml b/.github/workflows/copy-workflow.yml index ae8c8f5f..6b8c5f9b 100644 --- a/.github/workflows/copy-workflow.yml +++ b/.github/workflows/copy-workflow.yml @@ -111,14 +111,20 @@ jobs: config=$(echo -e "$config" | jq -c '.') github="{\"default_branch\":\"${{ env.DEFAULT_BRANCH }}\"}" context="{\"config\":$config,\"github\":$github}" + # matches trimmed string between template context delimiters regexp='\$\{\{\{\s*(.*?)\s*\}\}\}' + # replacement is a perl script that: + # 1. prepends . to the matched string to create a filter + # 2. escapes single quotes by replacing ' with '"'"' in filter + # 3. prints context escaped in the same manner + # 4. applies jq with filter to the stdout replacement="\$filter = \".\$1\"; \$filter =~ s/'/'\"'\"'/g; \`echo '${context//\'/\'\"\'\"\'}' | jq -jc '\$filter'\`" for f in $(jq -r '.[]' <<< ${{ toJson(env.FILES) }}); do echo -e "\nProcessing $f." # add DO NOT EDIT header tmp=$(mktemp) cat $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/header.yml $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f > $tmp - # replace template expressions with values from the JSON context object + # replace template contexts with values from the JSON context object perl -pi -e "s#$regexp#$replacement#ge" $tmp mv $tmp $TEMPLATE_REPO_DIR/$TEMPLATE_DIR/$f # create commit, if necessary diff --git a/templates/README.md b/templates/README.md index 7d3feb11..de2aa96d 100644 --- a/templates/README.md +++ b/templates/README.md @@ -2,6 +2,10 @@ This directory contains template files that can be expanded and copied over to the configured repositories. +## Header + +The [header](header.yml) is prepended to all the files before they are copied to the target repositories. + ## Contexts You can access context information during template expansion(before copy is performed). @@ -38,7 +42,7 @@ The `config` context is the configuration object because of which the file is be The `github` context contains information about the target repository the file is being copied to. | Property name | Type | Always present | Description | -| --- | --- | --- | +| --- | --- | --- | --- | | `github` | `object` | `true` | The top-level context. | | `github.default_branch` | `string` | `true` | The name of the default branch of the target repository. | @@ -53,7 +57,7 @@ The `github` context contains information about the target repository the file i "greeting": "Hello" }, "files": [], - "extra_files": [".github/workflows/example.yml"] + "extra_files": [".github/workflows/example.yml"], "target": "protocol/.github-test-target" }, "github": { From 0f14645043d6904e83e16cfa465f2feb48a0e22a Mon Sep 17 00:00:00 2001 From: galargh Date: Wed, 22 Dec 2021 17:22:48 +0100 Subject: [PATCH 39/44] trust workflows published in ipfs org --- .github/workflows/check-3rd-party.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-3rd-party.sh b/.github/workflows/check-3rd-party.sh index 112f85fd..a539019e 100755 --- a/.github/workflows/check-3rd-party.sh +++ b/.github/workflows/check-3rd-party.sh @@ -11,12 +11,13 @@ for line in `sed -ne 's/[[:space:]-]*uses:[[:space:]]*//p' $1 | sed -e 's/\s*#.* # - .: local workflows # "actions": workflows authored by GitHub # "protocol": workflows published in the protocol org - if [[ $author == "." || $author == "actions" || $author == "protocol" ]]; then continue; fi + # "ipfs": workflows published in the ipfs org + if [[ $author == "." || $author == "actions" || $author == "protocol" || $author == "ipfs" ]]; then continue; fi version=`echo $line | awk -F@ '{print $2}' | awk '{print $1}'` if ! [[ "$version" =~ ^[a-f0-9]{40}$ ]]; then status=1 echo "$FILE includes $line and doesn't use commit hash" fi -done +done exit $status From 5ddc3beffec5c1fb848494fdfbb6ece07bd8b10c Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 10 Jan 2022 10:23:59 +0100 Subject: [PATCH 40/44] move go-ipfs config from go.json to custom.json --- configs/README.md | 1 + configs/custom.json | 15 +++++++++++++++ configs/go.json | 10 ---------- 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 configs/custom.json diff --git a/configs/README.md b/configs/README.md index 9d51d514..a610050f 100644 --- a/configs/README.md +++ b/configs/README.md @@ -6,6 +6,7 @@ This directory contains config files used for workflow dispatch. | --- | --- | | go | repositories containing Go code | | testing | repositories used for testing unified CI workflows | +| custom | repositories not ready for full unified CI | ## Adding new repository to existing config file diff --git a/configs/custom.json b/configs/custom.json new file mode 100644 index 00000000..b63150e7 --- /dev/null +++ b/configs/custom.json @@ -0,0 +1,15 @@ +{ + "defaults": { + "files": [] + }, + "repositories": [ + { + "target": "ipfs/go-ipfs", + "files": [ + ".github/workflows/automerge.yml", + ".github/workflows/sync-release-assets.yml" + ], + "dist": "go-ipfs" + } + ] +} diff --git a/configs/go.json b/configs/go.json index ce835452..1bb4651a 100644 --- a/configs/go.json +++ b/configs/go.json @@ -52,16 +52,6 @@ { "target": "ipfs/go-filestore" }, { "target": "ipfs/go-fs-lock" }, { "target": "ipfs/go-graphsync" }, - { - "target": "ipfs/go-ipfs", - "files": [ - ".github/workflows/automerge.yml", - ".github/workflows/sync-release-assets.yml" - ], - "dist": "go-ipfs", - "deploy_versioning": false, - "deploy_go": false - }, { "target": "ipfs/go-ipfs-api" }, { "target": "ipfs/go-ipfs-blockstore" }, { "target": "ipfs/go-ipfs-blocksutil" }, From 406b18365f417643ce1aaf92916f3b2a49868f37 Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Mon, 10 Jan 2022 10:59:14 +0100 Subject: [PATCH 41/44] Update templates/README.md Co-authored-by: Marten Seemann --- templates/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/README.md b/templates/README.md index de2aa96d..33c52783 100644 --- a/templates/README.md +++ b/templates/README.md @@ -8,7 +8,7 @@ The [header](header.yml) is prepended to all the files before they are copied to ## Contexts -You can access context information during template expansion(before copy is performed). +You can access context information during template expansion (before copy is performed). ### About contexts From 676e4905ddea2065df45b02b515a75d7179af45a Mon Sep 17 00:00:00 2001 From: galargh Date: Mon, 10 Jan 2022 13:09:03 +0100 Subject: [PATCH 42/44] describe how context container is created --- templates/README.md | 68 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/templates/README.md b/templates/README.md index 33c52783..a6ea6a2f 100644 --- a/templates/README.md +++ b/templates/README.md @@ -23,9 +23,11 @@ ${{{ }}} | `config` | `object` | Configuration object because of which the file is being copied. For more information, see [config context](#config-context) | | `github` | `object` | Information about the target repository the file is being copied to. For more information, see [github context](#github-context) | +The context container is generated automatically before template expansion is performed. + #### `config` context -The `config` context is the configuration object because of which the file is being copied. +The `config` context is the configuration object because of which the file is being copied. It is created by merging the `defaults` object with a `repository` object (from the `repositories` array) from a JSON configuration file. | Property name | Type | Always present | Description | | --- | --- | --- | --- | @@ -39,7 +41,7 @@ The `config` context is the configuration object because of which the file is be #### `github` context -The `github` context contains information about the target repository the file is being copied to. +The `github` context contains information about the target repository the file is being copied to. It is created on the fly before template expansion is performed. | Property name | Type | Always present | Description | | --- | --- | --- | --- | @@ -48,25 +50,49 @@ The `github` context contains information about the target repository the file i ### Examples +#### JSON configuration + +```json +{ + "defaults": { + "files": [".github/workflows/automerge.yml"], + "is_example": false + }, + "repositories": [ + { + "target": "protocol/.github-test-target", + "extra_files": [".github/workflows/example.yml"], + "example": { + "greeting": "Hello" + }, + "is_example": true + } + ] +} +``` + #### Context container +*created automatically before template expansion is performed* + ```json { - "config": { - "example": { - "greeting": "Hello" - }, - "files": [], - "extra_files": [".github/workflows/example.yml"], - "target": "protocol/.github-test-target" + "config": { + "target": "protocol/.github-test-target", + "files": [".github/workflows/automerge.yml"], + "extra_files": [".github/workflows/example.yml"], + "example": { + "greeting": "Hello" }, - "github": { - "default_branch": "master" - } + "is_example": true + }, + "github": { + "default_branch": "master" + } } ``` -#### Template expanding context +#### Template ```yaml name: Hello @@ -81,3 +107,19 @@ jobs: - run: echo ${{{ config.example.greeting }}} shell: bash ``` + +#### Expanded template + +```yaml +name: Hello +on: + push: + branches: + - master +jobs: + echo: + runs-on: ubuntu-latest + steps: + - run: echo Hello + shell: bash +``` From 01192c56d290ef9128eeddb8857a95bfcf2a6d06 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 3 Jan 2023 09:33:01 +0100 Subject: [PATCH 43/44] Revert: creation of sync-release-assets.yml workflow --- .github/workflows/sync-release-assets.yml | 139 ------------------ configs/README.md | 1 - configs/custom.json | 15 -- configs/go.json | 6 +- .../.github/workflows/sync-release-assets.yml | 11 -- 5 files changed, 1 insertion(+), 171 deletions(-) delete mode 100644 .github/workflows/sync-release-assets.yml delete mode 100644 configs/custom.json delete mode 100644 templates/.github/workflows/sync-release-assets.yml diff --git a/.github/workflows/sync-release-assets.yml b/.github/workflows/sync-release-assets.yml deleted file mode 100644 index 7de25d5e..00000000 --- a/.github/workflows/sync-release-assets.yml +++ /dev/null @@ -1,139 +0,0 @@ -name: Sync github release assets with dist.ipfs.io -on: - workflow_call: - inputs: - dist: - required: true - type: string - -concurrency: - group: release-assets-dist-sync - cancel-in-progress: true - -jobs: - sync-github-and-dist-ipfs-io: - runs-on: "ubuntu-latest" - steps: - - uses: ipfs/download-ipfs-distribution-action@v1 - - uses: ipfs/start-ipfs-daemon-action@v1 - with: - args: --init --init-profile=flatfs,server --enable-gc=false - - uses: actions/setup-node@v2 - with: - node-version: 14 - - name: Sync the latest 5 github releases - uses: actions/github-script@v4 - with: - script: | - const fs = require('fs').promises - const max_synced = 5 - - // fetch github releases - resp = await github.repos.listReleases({ - owner: context.repo.owner, - repo: context.repo.repo, - page: 1, - per_page: max_synced - }) - const release_assets = []; - num_synced = 0; - for (const release of resp.data) { - console.log("checking release tagged", release.tag_name) - if (release.draft || release.prerelease) { - console.log("skipping draft/prerelease tagged", release.tag_name) - continue - } - if (num_synced > max_synced) { - console.log("done: synced", max_synced, "latest releases") - break; - } - num_synced += 1 - - const github_assets = new Set() - for (const asset of release.assets) { - github_assets.add(asset.name) - } - - // fetch asset info from dist.ipfs.io - p = '/ipns/dist.ipfs.io/${{ inputs.dist }}/' + release.tag_name - let stdout = '' - const options = {} - options.listeners = { - stdout: (data) => { - stdout += data.toString(); - } - } - await exec.exec('ipfs', ['ls', p], options) - - const dist_assets = new Set() - const missing_files = [] - for (const raw_line of stdout.split("\n")) { - line = raw_line.trim(); - if (line.length != 0) { - file = line.split(/(\s+)/).filter( function(e) { return e.trim().length > 0; } )[2] - dist_assets.add(file) - if (!github_assets.has(file)) { - missing_files.push(file) - } - } - } - - // if dist.ipfs.io has files not found in github, copy them over - for (const file of missing_files) { - file_sha = file + ".sha512" - file_cid = file + ".cid" - - // skip files that don't have .cid and .sha512 checksum files - if (!dist_assets.has(file_sha) || !dist_assets.has(file_cid)) { - if (!file.endsWith('.cid') && !file.endsWith('.sha512')) { // silent skip of .sha512.sha512 :) - console.log(`skipping "${file}" as dist.ipfs.io does not provide .cid and .sha512 checksum files for it`) - } - continue - } - - console.log("fetching", file, "from dist.ipfs.io") - await exec.exec('ipfs', ['get', p + '/' + file]) - await exec.exec('ipfs', ['get', p + '/' + file_sha]) - await exec.exec('ipfs', ['get', p + '/' + file_cid]) - console.log("verifying contents of", file) - - // compute sha512 output for file - let sha_stdout = '' - const sha_options = {} - sha_options.listeners = { - stdout: (data) => { - sha_stdout += data.toString(); - } - } - await exec.exec('sha512sum', [file], sha_options) - // read expected sha512 output - const sha_data = await fs.readFile(file_sha, "utf8") - const digest = (s) => s.split(' ').shift() - if (digest(sha_data) != digest(sha_stdout)) { - console.log(`${file}.sha512: ${sha_data}`) - console.log(`sha512sum ${file}: ${sha_stdout}`) - throw "checksum verification failed for " + file - } - - console.log("uploading", file, "to github release", release.tag_name) - const uploadReleaseAsset = async (file) => github.repos.uploadReleaseAsset({ - owner: context.repo.owner, - repo: context.repo.repo, - release_id: release.id, - headers: { - "content-type": "application/octet-stream", - "content-length": `${(await fs.stat(file)).size}` - }, - name: file, - data: await fs.readFile(file) - }) - await uploadReleaseAsset(file) - await uploadReleaseAsset(file_sha) - await uploadReleaseAsset(file_cid) - - } - // summary of assets on both sides - release_assets.push({ tag: release.tag_name, github_assets, dist_assets }) - } - console.log(release_assets) - return release_assets diff --git a/configs/README.md b/configs/README.md index cea3880f..1c6a2775 100644 --- a/configs/README.md +++ b/configs/README.md @@ -7,7 +7,6 @@ This directory contains config files used for workflow dispatch. | go | repositories containing Go code | | js | repositories containing JS code | | testing | repositories used for testing Unified CI workflows | -| custom | repositories not ready for full unified CI | ## Adding new repository to existing config file diff --git a/configs/custom.json b/configs/custom.json deleted file mode 100644 index b63150e7..00000000 --- a/configs/custom.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "defaults": { - "files": [] - }, - "repositories": [ - { - "target": "ipfs/go-ipfs", - "files": [ - ".github/workflows/automerge.yml", - ".github/workflows/sync-release-assets.yml" - ], - "dist": "go-ipfs" - } - ] -} diff --git a/configs/go.json b/configs/go.json index ae631209..8fa73bb0 100644 --- a/configs/go.json +++ b/configs/go.json @@ -413,11 +413,7 @@ "target": "libp2p/go-libp2p-record" }, { - "target": "libp2p/go-libp2p-relay-daemon", - "extra_files": [ - ".github/workflows/sync-release-assets.yml" - ], - "dist": "libp2p-relay-daemon" + "target": "libp2p/go-libp2p-relay-daemon" }, { "target": "libp2p/go-libp2p-routing-helpers" diff --git a/templates/.github/workflows/sync-release-assets.yml b/templates/.github/workflows/sync-release-assets.yml deleted file mode 100644 index b1e0f621..00000000 --- a/templates/.github/workflows/sync-release-assets.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Sync github release assets with dist.ipfs.io -on: - workflow_dispatch: - schedule: - - cron: '0 0 * * *' - -jobs: - sync-github-and-dist-ipfs-io: - uses: protocol/.github/.github/workflows/sync-release-assets.yml@master - with: - dist: ${{{ config.dist }}} From 731f34cec6b643a23e266af3c96fb6b5e0ab2ba1 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 3 Jan 2023 09:33:23 +0100 Subject: [PATCH 44/44] Revert "Revert: creation of sync-release-assets.yml workflow" This reverts commit 01192c56d290ef9128eeddb8857a95bfcf2a6d06. --- .github/workflows/sync-release-assets.yml | 139 ++++++++++++++++++ configs/README.md | 1 + configs/custom.json | 15 ++ configs/go.json | 6 +- .../.github/workflows/sync-release-assets.yml | 11 ++ 5 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/sync-release-assets.yml create mode 100644 configs/custom.json create mode 100644 templates/.github/workflows/sync-release-assets.yml diff --git a/.github/workflows/sync-release-assets.yml b/.github/workflows/sync-release-assets.yml new file mode 100644 index 00000000..7de25d5e --- /dev/null +++ b/.github/workflows/sync-release-assets.yml @@ -0,0 +1,139 @@ +name: Sync github release assets with dist.ipfs.io +on: + workflow_call: + inputs: + dist: + required: true + type: string + +concurrency: + group: release-assets-dist-sync + cancel-in-progress: true + +jobs: + sync-github-and-dist-ipfs-io: + runs-on: "ubuntu-latest" + steps: + - uses: ipfs/download-ipfs-distribution-action@v1 + - uses: ipfs/start-ipfs-daemon-action@v1 + with: + args: --init --init-profile=flatfs,server --enable-gc=false + - uses: actions/setup-node@v2 + with: + node-version: 14 + - name: Sync the latest 5 github releases + uses: actions/github-script@v4 + with: + script: | + const fs = require('fs').promises + const max_synced = 5 + + // fetch github releases + resp = await github.repos.listReleases({ + owner: context.repo.owner, + repo: context.repo.repo, + page: 1, + per_page: max_synced + }) + const release_assets = []; + num_synced = 0; + for (const release of resp.data) { + console.log("checking release tagged", release.tag_name) + if (release.draft || release.prerelease) { + console.log("skipping draft/prerelease tagged", release.tag_name) + continue + } + if (num_synced > max_synced) { + console.log("done: synced", max_synced, "latest releases") + break; + } + num_synced += 1 + + const github_assets = new Set() + for (const asset of release.assets) { + github_assets.add(asset.name) + } + + // fetch asset info from dist.ipfs.io + p = '/ipns/dist.ipfs.io/${{ inputs.dist }}/' + release.tag_name + let stdout = '' + const options = {} + options.listeners = { + stdout: (data) => { + stdout += data.toString(); + } + } + await exec.exec('ipfs', ['ls', p], options) + + const dist_assets = new Set() + const missing_files = [] + for (const raw_line of stdout.split("\n")) { + line = raw_line.trim(); + if (line.length != 0) { + file = line.split(/(\s+)/).filter( function(e) { return e.trim().length > 0; } )[2] + dist_assets.add(file) + if (!github_assets.has(file)) { + missing_files.push(file) + } + } + } + + // if dist.ipfs.io has files not found in github, copy them over + for (const file of missing_files) { + file_sha = file + ".sha512" + file_cid = file + ".cid" + + // skip files that don't have .cid and .sha512 checksum files + if (!dist_assets.has(file_sha) || !dist_assets.has(file_cid)) { + if (!file.endsWith('.cid') && !file.endsWith('.sha512')) { // silent skip of .sha512.sha512 :) + console.log(`skipping "${file}" as dist.ipfs.io does not provide .cid and .sha512 checksum files for it`) + } + continue + } + + console.log("fetching", file, "from dist.ipfs.io") + await exec.exec('ipfs', ['get', p + '/' + file]) + await exec.exec('ipfs', ['get', p + '/' + file_sha]) + await exec.exec('ipfs', ['get', p + '/' + file_cid]) + console.log("verifying contents of", file) + + // compute sha512 output for file + let sha_stdout = '' + const sha_options = {} + sha_options.listeners = { + stdout: (data) => { + sha_stdout += data.toString(); + } + } + await exec.exec('sha512sum', [file], sha_options) + // read expected sha512 output + const sha_data = await fs.readFile(file_sha, "utf8") + const digest = (s) => s.split(' ').shift() + if (digest(sha_data) != digest(sha_stdout)) { + console.log(`${file}.sha512: ${sha_data}`) + console.log(`sha512sum ${file}: ${sha_stdout}`) + throw "checksum verification failed for " + file + } + + console.log("uploading", file, "to github release", release.tag_name) + const uploadReleaseAsset = async (file) => github.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release.id, + headers: { + "content-type": "application/octet-stream", + "content-length": `${(await fs.stat(file)).size}` + }, + name: file, + data: await fs.readFile(file) + }) + await uploadReleaseAsset(file) + await uploadReleaseAsset(file_sha) + await uploadReleaseAsset(file_cid) + + } + // summary of assets on both sides + release_assets.push({ tag: release.tag_name, github_assets, dist_assets }) + } + console.log(release_assets) + return release_assets diff --git a/configs/README.md b/configs/README.md index 1c6a2775..cea3880f 100644 --- a/configs/README.md +++ b/configs/README.md @@ -7,6 +7,7 @@ This directory contains config files used for workflow dispatch. | go | repositories containing Go code | | js | repositories containing JS code | | testing | repositories used for testing Unified CI workflows | +| custom | repositories not ready for full unified CI | ## Adding new repository to existing config file diff --git a/configs/custom.json b/configs/custom.json new file mode 100644 index 00000000..b63150e7 --- /dev/null +++ b/configs/custom.json @@ -0,0 +1,15 @@ +{ + "defaults": { + "files": [] + }, + "repositories": [ + { + "target": "ipfs/go-ipfs", + "files": [ + ".github/workflows/automerge.yml", + ".github/workflows/sync-release-assets.yml" + ], + "dist": "go-ipfs" + } + ] +} diff --git a/configs/go.json b/configs/go.json index 8fa73bb0..ae631209 100644 --- a/configs/go.json +++ b/configs/go.json @@ -413,7 +413,11 @@ "target": "libp2p/go-libp2p-record" }, { - "target": "libp2p/go-libp2p-relay-daemon" + "target": "libp2p/go-libp2p-relay-daemon", + "extra_files": [ + ".github/workflows/sync-release-assets.yml" + ], + "dist": "libp2p-relay-daemon" }, { "target": "libp2p/go-libp2p-routing-helpers" diff --git a/templates/.github/workflows/sync-release-assets.yml b/templates/.github/workflows/sync-release-assets.yml new file mode 100644 index 00000000..b1e0f621 --- /dev/null +++ b/templates/.github/workflows/sync-release-assets.yml @@ -0,0 +1,11 @@ +name: Sync github release assets with dist.ipfs.io +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * *' + +jobs: + sync-github-and-dist-ipfs-io: + uses: protocol/.github/.github/workflows/sync-release-assets.yml@master + with: + dist: ${{{ config.dist }}}