@@ -50,3 +50,139 @@ jobs:
50
50
path : |
51
51
qtv-go*
52
52
compression-level : 9
53
+
54
+ upload :
55
+ if : github.repository == 'QW-group/qtv-go' && ((github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event_name == 'release')
56
+ needs : [build]
57
+ runs-on : ubuntu-latest
58
+ steps :
59
+ - name : Download Artifacts
60
+ uses : actions/download-artifact@v4
61
+ with :
62
+ path : artifacts
63
+
64
+ - name : Get release date
65
+ run : |
66
+ RELEASE_DATE=$(git log -1 --format=%cI "${{ github.ref_name }}")
67
+ echo "RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV
68
+ working-directory : ezquake
69
+ if : github.event_name == 'release'
70
+
71
+ - name : Collect GitHub release artifacts
72
+ run : |
73
+ set -e
74
+
75
+ dist_dir="${GITHUB_WORKSPACE}/dist"
76
+ mkdir "${dist_dir}"
77
+
78
+ # Reset timestamp to time of commit before compression
79
+ find "artifacts" -type f -exec touch --date="${RELEASE_DATE}" {} +
80
+
81
+ # Set executable bit for all files
82
+ find "artifacts" -type f -exec chmod 755 {} +
83
+
84
+ # Recompress before attaching to release, avoiding double-zip of macOS
85
+ (
86
+ cd artifacts
87
+ for target in *; do
88
+ (cd "${target}"; zip -o -9 "${dist_dir}/${target}.zip" *)
89
+ done;
90
+ )
91
+
92
+ (cd "artifacts"; find . -type f -execdir sha256sum {} \; > "${dist_dir}/checksums.txt")
93
+
94
+ # Reset timestamp to time of commit for all release artifacts
95
+ find "${dist_dir}" -type f -exec touch --date="${RELEASE_DATE}" {} +
96
+
97
+ echo "Release artifacts:"
98
+ ls -lR "${dist_dir}"
99
+
100
+ echo "Checksums:"
101
+ cat "${dist_dir}/checksums.txt"
102
+
103
+ echo "GITHUB_ARTIFACTS=${dist_dir}" >> $GITHUB_ENV
104
+ if : github.event_name == 'release'
105
+
106
+ - name : Attach artifacts to GitHub release
107
+ uses : softprops/action-gh-release@v2
108
+ with :
109
+ files : ${{ env.GITHUB_ARTIFACTS }}/*
110
+ env :
111
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
112
+ if : github.event_name == 'release'
113
+
114
+ - name : Prepare Upload Environemnt
115
+ run : |
116
+ sudo apt-get -qq update
117
+ sudo apt-get -qq --no-install-recommends install openssh-client
118
+
119
+ - name : Setup SSH
120
+ run : |
121
+ ssh-agent -a $SSH_AUTH_SOCK > /dev/null
122
+ ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
123
+ env :
124
+ SSH_AUTH_SOCK : /tmp/ssh_agent.sock
125
+
126
+ - name : Prepare upload to builds.quakeworld.nu
127
+ run : |
128
+ # Build file structure for uploading
129
+ # snapshots:
130
+ # upload/snapshots/latest/$os/$arch/$filename
131
+ # upload/snapshots/$os/$arch/$prefix_$filename
132
+ # releases:
133
+ # upload/releases/latest/$os/$arch/$filename
134
+ # upload/releases/$tag/$os/$arch/$filename
135
+
136
+ set -e
137
+
138
+ # TODO...
139
+ upload_dir="${GITHUB_WORKSPACE}/upload"
140
+ if [[ $GITHUB_REF == refs/tags/* ]]; then
141
+ main_dir="${upload_dir}/releases/${{ github.ref_name }}"
142
+ latest_dir="${upload_dir}/releases/latest"
143
+ prefix=""
144
+ upload_prefix="releases"
145
+ else
146
+ main_dir="${upload_dir}/snapshots"
147
+ latest_dir="${upload_dir}/snapshots/latest"
148
+ date=$(TZ="Europe/Amsterdam" date "+%Y%m%d-%H%M%S")
149
+ prefix="${date}_${GITHUB_SHA::7}_"
150
+ upload_prefix="snapshots"
151
+ fi
152
+
153
+ # Collect upload structure
154
+ for artifact in artifacts/*/*; do
155
+ artifact_file=$(basename "${artifact}")
156
+ artifact_dir=$(dirname "${artifact}")
157
+
158
+ IFS='-' read -r ezq os arch <<< "${artifact_dir}"
159
+
160
+ mkdir -p "${main_dir}/${os}/${arch}" "${latest_dir}/${os}/${arch}"
161
+
162
+ cp "${artifact}" "${main_dir}/${os}/${arch}/${prefix}${artifact_file}"
163
+ cp "${artifact}" "${latest_dir}/${os}/${arch}/${artifact_file}"
164
+ done
165
+
166
+ # Set executable bit for all files
167
+ find "${upload_dir}" -type f -exec chmod 755 {} +
168
+
169
+ # Generate checksums
170
+ for artifact in $(find "${upload_dir}" -type f); do
171
+ artifact_file=$(basename "${artifact}")
172
+ artifact_dir=$(dirname "${artifact}")
173
+ (cd "${artifact_dir}" && md5sum "${artifact_file}" > "${artifact_file}.md5")
174
+ done
175
+
176
+ # Reset timestamp to time of commit
177
+ find "${upload_dir}" -type f -exec touch --date="${RELEASE_DATE}" {} +
178
+
179
+ echo "Upload artifacts:"
180
+ ls -lR "${upload_dir}"
181
+
182
+ echo "UPLOAD_PREFIX=${upload_prefix}" >> $GITHUB_ENV
183
+
184
+ - name : Upload to builds.quakeworld.nu
185
+ env :
186
+ SSH_AUTH_SOCK : /tmp/ssh_agent.sock
187
+ run : |
188
+ sftp -rp -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' -P ${{ secrets.SFTP_PORT }} ${{ secrets.SFTP_USERNAME }}@${{ secrets.SFTP_HOST }}:/${{ env.UPLOAD_PREFIX }} <<< $'put -rp upload/${{ env.UPLOAD_PREFIX }}/*'
0 commit comments