1
+ # .github/workflows/mirror.yml
2
+ name : " Mirror repository artifacts"
3
+ on :
4
+ repository_dispatch :
5
+ types : ["Mirror"]
6
+
7
+ env :
8
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9
+ PULL_REPOSITORY : " ${{ github.event.client_payload.pull_repository }}" # username/repository
10
+ CDN_TAG : " ${{ github.event.client_payload.cdn_tag }}" # folder on server
11
+ PULL_TAG : " " # leave empty for latest
12
+
13
+ jobs :
14
+
15
+ prepare :
16
+ name : " Split JSON into parts"
17
+ runs-on : " ubuntu-24.04"
18
+ outputs :
19
+ matrix : ${{steps.json.outputs.JSON_CONTENT}}
20
+ steps :
21
+ - name : " Install SSH key"
22
+ uses : shimataro/ssh-key-action@v2
23
+ with :
24
+ key : " ${{ secrets.KEY_UPLOAD }}"
25
+ known_hosts : " ${{ secrets.KNOWN_HOSTS_ARMBIAN_UPLOAD }}"
26
+ if_key_exists : replace
27
+ - name : " Get latest release TAG"
28
+ run : |
29
+ echo "LATEST=$(gh release list --repo https://github.com/${{ env.PULL_REPOSITORY }} --json isLatest,tagName | jq -r '.[] | select(.isLatest == true) | .tagName')" >> $GITHUB_ENV
30
+ - name : " Get upload servers"
31
+ run : |
32
+ curl -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" \
33
+ -H "Accept: application/json; indent=4" \
34
+ "https://stuff.armbian.com/netbox/api/virtualization/virtual-machines/?limit=500&name__empty=false&status=active" | \
35
+ jq '.results[] | select(.tags.[].name == "cache") | {name, custom_fields}' > servers.json
36
+ - name : " Get release artefacts"
37
+ run : |
38
+ gh release view --json \
39
+ assets --repo https://github.com/${{ env.PULL_REPOSITORY }} | \
40
+ jq '.assets[] | { "tag": "'${{ env.LATEST }}'","cdn_tag": "'${{ env.CDN_TAG }}'", name: .name, url: .url, size: .size}' | \
41
+ jq -s > artifacts.json
42
+ - name : " Split JSON file into parts"
43
+ run : |
44
+ cat >> "split.py" <<- EOT
45
+ import json
46
+ def split_json(input_file, output_prefix, chunk_size):
47
+ # Open and load the large JSON file
48
+ with open(input_file, 'r') as infile:
49
+ data = json.load(infile)
50
+ # Split the data into chunks
51
+ total_chunks = len(data) // chunk_size + (1 if len(data) % chunk_size != 0 else 0)
52
+ for i in range(total_chunks):
53
+ chunk = data[i * chunk_size:(i + 1) * chunk_size]
54
+ output_filename = f"{output_prefix}_{i + 1}.json"
55
+ # Write each chunk into a separate JSON file
56
+ with open(output_filename, 'w') as outfile:
57
+ json.dump(chunk, outfile, indent=4)
58
+ split_json('artifacts.json', 'part', 200)
59
+ EOT
60
+ python3 split.py
61
+ - name : " Upload JSON parts"
62
+ uses : actions/upload-artifact@v4
63
+ with :
64
+ name : parts
65
+ path : |
66
+ part*
67
+ servers.json
68
+ if-no-files-found : ignore
69
+ compression-level : 9
70
+ - name : " Make JSON"
71
+ id : json
72
+ run : |
73
+ echo 'JSON_CONTENT<<EOF' >> $GITHUB_OUTPUT
74
+ find * -name "part*.json" -type f -exec stat --format '{"latest": "'${{ env.LATEST }}'","cdn_tag": "'${{ env.CDN_TAG }}'","name": "%n"}' {} \; | jq -s . >> $GITHUB_OUTPUT
75
+ echo 'EOF' >> $GITHUB_OUTPUT
76
+ gradle :
77
+ needs : prepare
78
+ name : " JSON: ${{ matrix.name }}"
79
+ strategy :
80
+ fail-fast : false
81
+ matrix :
82
+ include : ${{ fromJson(needs.prepare.outputs.matrix) }}
83
+ uses : armbian/armbian.github.io/.github/workflows/reusable.yml@mirror
84
+ with :
85
+ name : " ${{ matrix.name }}"
86
+ cdntag : " ${{ matrix.cdn_tag }}"
87
+ latest : " ${{ matrix.latest }}"
88
+ secrets :
89
+ KEY_UPLOAD : ${{ secrets.KEY_UPLOAD }}
90
+ KNOWN_HOSTS_ARMBIAN_UPLOAD : ${{ secrets.KNOWN_HOSTS_ARMBIAN_UPLOAD }}
91
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
92
+
93
+ cleanup :
94
+ needs : gradle
95
+ name : " Cleaning"
96
+ runs-on : " ubuntu-24.04"
97
+ steps :
98
+ - name : " Install SSH key"
99
+ uses : shimataro/ssh-key-action@v2
100
+ with :
101
+ key : " ${{ secrets.KEY_UPLOAD }}"
102
+ known_hosts : " ${{ secrets.KNOWN_HOSTS_ARMBIAN_UPLOAD }}"
103
+ if_key_exists : replace
104
+ - name : Download ${{ matrix.name }}
105
+ uses : actions/download-artifact@v4
106
+ with :
107
+ name : parts
108
+ pattern : part*
109
+ merge-multiple : true
110
+ - name : " Make JSON"
111
+ id : json
112
+ run : |
113
+ LATEST=$(cat part*.json | jq -r '.[].tag' | sort | uniq)
114
+ CDN_TAG=$(cat part*.json | jq -r '.[].cdn_tag' | sort | uniq)
115
+ echo "Delete all except $LATEST on $CDN_TAG"
116
+ tempfolder=$(mktemp -d)
117
+ rsync --delete -e \
118
+ "ssh -p 10023 -o StrictHostKeyChecking=accept-new" \
119
+ -rvP ${tempfolder}/ "[email protected] :/storage/www/cache/${CDN_TAG}" --exclude=${LATEST}
120
+
121
+ - uses : geekyeggo/delete-artifact@v5
122
+ with :
123
+ name : |
124
+ parts*
0 commit comments