@cryptotaxi247 / kubo / commits / 2bb2f64c4

feat(ci): attach release assets from dist.ipfs.io (#8494)

Periodically compare release assets in dist.ipfs.io and github. Any assets found in dist.ipfs.io and not in github are copied over.

Petar Maymounkov committed Oct 15, 2021 at 08:38 UTC 2bb2f64c409081e6c57f3f5400609087d8d077a5
1 file changed +124
.github/workflows/sync-release-assets.yml new
+124
@@ -0,0 +1,124 @@
1 +name: Sync github release assets with dist.ipfs.io
2 +
3 +on:
4 + workflow_dispatch:
5 + schedule:
6 + - cron: '0 0 * * *'
7 +
8 +concurrency:
9 + group: release-assets-dist-sync
10 + cancel-in-progress: true
11 +
12 +jobs:
13 + sync-github-and-dist-ipfs-io:
14 + runs-on: "ubuntu-latest"
15 + steps:
16 + - name: Setup go
17 + uses: actions/setup-go@v2
18 + with:
19 + go-version: '1.16'
20 + - uses: actions/cache@v2
21 + with:
22 + path: |
23 + ~/.cache/go-build
24 + ~/go/pkg/mod
25 + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
26 + restore-keys: |
27 + ${{ runner.os }}-go-
28 + - name: Build go-ipfs binary
29 + run: go install github.com/ipfs/go-ipfs/cmd/ipfs@latest
30 + - name: Initialize go-ipfs and start daemon
31 + run: |
32 + sudo sysctl -w net.core.rmem_max=2500000
33 + ipfs init --profile flatfs,server
34 + ipfs daemon --enable-gc=false &
35 + while (! ipfs id --api "/ip4/127.0.0.1/tcp/5001"); do sleep 1; done
36 + - name: Wait for go-ipfs to be ready
37 + shell: pwsh
38 + run: |
39 + for ($i = 0; $i -lt 10; $i++) {
40 + $addrs = ipfs id | jq .Addresses;
41 + if ($addrs -eq "null") {
42 + sleep 1
43 + } else {
44 + echo "Successfully started the daemon"
45 + exit 0
46 + }
47 + }
48 + - uses: actions/setup-node@v2
49 + with:
50 + node-version: 14
51 + - name: Sync the latest 5 github releases
52 + uses: actions/github-script@v4
53 + with:
54 + script: |
55 + const fs = require('fs').promises
56 + const max_synced = 5
57 +
58 + // fetch github releases
59 + resp = await github.repos.listReleases({
60 + owner: context.repo.owner,
61 + repo: context.repo.repo,
62 + page: 1,
63 + per_page: max_synced
64 + })
65 + const release_assets = [];
66 + num_synced = 0;
67 + for (const release of resp.data) {
68 + console.log("checking release tagged", release.tag_name)
69 + if (num_synced > max_synced) {
70 + console.log("done: synced", max_synced, "latest releases")
71 + break;
72 + }
73 + num_synced += 1
74 +
75 + const github_assets = [];
76 + github_map = {};
77 + for (const asset of release.assets) {
78 + github_assets.push(asset.name);
79 + github_map[asset.name] = true;
80 + }
81 +
82 + // fetch asset info from dist.ipfs.io
83 + p = '/ipns/dist.ipfs.io/go-ipfs/' + release.tag_name
84 + let stdout = ''
85 + const options = {}
86 + options.listeners = {
87 + stdout: (data) => {
88 + stdout += data.toString();
89 + }
90 + }
91 + await exec.exec('ipfs', ['ls', p], options)
92 +
93 + const dist_assets = []
94 + missing_files = []
95 + for (const raw_line of stdout.split("\n")) {
96 + line = raw_line.trim();
97 + if (line.length != 0) {
98 + file = line.split(/(\s+)/).filter( function(e) { return e.trim().length > 0; } )[2]
99 + dist_assets.push(file)
100 + if (!github_map[file]) {
101 + missing_files.push(file)
102 + }
103 + }
104 + }
105 +
106 + // if dist.ipfs.io has files not found in github, copy them over
107 + for (const file of missing_files) {
108 + console.log("fetching", file, "from dist.ipfs.io")
109 + await exec.exec('ipfs', ['get', p + '/' + file])
110 + const data = await fs.readFile(file, "binary")
111 + console.log("uploading", file, "to github release", release.tag_name)
112 + resp = await github.repos.uploadReleaseAsset({
113 + owner: context.repo.owner,
114 + repo: context.repo.repo,
115 + release_id: release.id,
116 + name: file,
117 + data: data,
118 + })
119 + }
120 + // summary of assets on both sides
121 + release_assets.push({ tag: release.tag_name, github_assets: github_assets, dist_assets: dist_assets })
122 + }
123 + console.log(release_assets)
124 + return release_assets