Skip to content

Commit 9d5af3f

Browse files
authored
Improve upload artifact to builds.hex.pm workflow (#13845)
1 parent 6152ecb commit 9d5af3f

File tree

2 files changed

+119
-145
lines changed

2 files changed

+119
-145
lines changed

.github/workflows/builds.hex.pm.yml

Lines changed: 0 additions & 144 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
name: Docs
101101
path: Docs.zip*
102102

103-
upload:
103+
upload-release:
104104
needs: build
105105
runs-on: windows-2022
106106

@@ -149,3 +149,121 @@ jobs:
149149
elixir-otp-*.exe.sha{1,256}sum \
150150
Docs.zip \
151151
Docs.zip.sha{1,256}sum
152+
153+
upload-builds-hex-pm:
154+
needs: build
155+
runs-on: ubuntu-22.04
156+
concurrency: builds-hex-pm
157+
env:
158+
AWS_ACCESS_KEY_ID: ${{ secrets.HEX_AWS_ACCESS_KEY_ID }}
159+
AWS_SECRET_ACCESS_KEY: ${{ secrets.HEX_AWS_SECRET_ACCESS_KEY }}
160+
AWS_REGION: ${{ secrets.HEX_AWS_REGION }}
161+
AWS_S3_BUCKET: ${{ secrets.HEX_AWS_S3_BUCKET }}
162+
FASTLY_REPO_SERVICE_ID: ${{ secrets.HEX_FASTLY_REPO_SERVICE_ID }}
163+
FASTLY_BUILDS_SERVICE_ID: ${{ secrets.HEX_FASTLY_BUILDS_SERVICE_ID }}
164+
FASTLY_KEY: ${{ secrets.HEX_FASTLY_KEY }}
165+
OTP_GENERIC_VERSION: '25'
166+
steps:
167+
- uses: actions/download-artifact@v4
168+
169+
- name: Init purge keys file
170+
run: |
171+
touch purge_keys.txt
172+
173+
- name: Upload Precompiled to S3
174+
run: |
175+
ref_name=${{ github.ref_name }}
176+
177+
mv elixir-otp-*/* .
178+
for zip in $(find . -type f -name 'elixir-otp-*.zip' | sed 's/^\.\///'); do
179+
dest=${zip/elixir/${ref_name}}
180+
surrogate_key=${dest/.zip$/}
181+
182+
aws s3 cp "${zip}" "s3://${AWS_S3_BUCKET}/builds/elixir/${dest}" \
183+
--cache-control "public,max-age=3600" \
184+
--metadata "{\"surrogate-key\":\"builds builds/elixir builds/elixir/${surrogate_key}\",\"surrogate-control\":\"public,max-age=604800\"}"
185+
echo "builds/elixir/${surrogate_key}" >> purge_keys.txt
186+
187+
if [ "$zip" == "elixir-otp-${OTP_GENERIC_VERSION}.zip" ]; then
188+
aws s3 cp "${zip}" "s3://${AWS_S3_BUCKET}/builds/elixir/${ref_name}.zip" \
189+
--cache-control "public,max-age=3600" \
190+
--metadata "{\"surrogate-key\":\"builds builds/elixir builds/elixir/${ref_name}\",\"surrogate-control\":\"public,max-age=604800\"}"
191+
echo builds/elixir/${ref_name} >> purge_keys.txt
192+
fi
193+
done
194+
195+
- name: Upload Docs to S3
196+
working-directory: Docs
197+
run: |
198+
version=$(echo ${{ github.ref_name }} | sed -e 's/^v//g')
199+
200+
unzip Docs.zip
201+
202+
for f in doc/*; do
203+
if [ -d "$f" ]; then
204+
app=$(echo "$f" | sed s/"doc\/"//)
205+
tarball="${app}-${version}.tar.gz"
206+
surrogate_key="docs/${app}-${version}"
207+
208+
tar -czf "${tarball}" -C "doc/${app}" .
209+
aws s3 cp "${tarball}" "s3://${AWS_S3_BUCKET}/docs/${tarball}" \
210+
--cache-control "public,max-age=3600" \
211+
--metadata "{\"surrogate-key\":\"${surrogate_key}\",\"surrogate-control\":\"public,max-age=604800\"}"
212+
echo "${surrogate_key}" >> ../purge_keys.txt
213+
fi
214+
done
215+
216+
- name: Update builds txt
217+
run: |
218+
date="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
219+
ref_name=${{ github.ref_name }}
220+
221+
aws s3 cp "s3://${AWS_S3_BUCKET}/builds/elixir/builds.txt" builds.txt || true
222+
touch builds.txt
223+
224+
for sha256_file in $(find . -name 'elixir-otp-*.zip.sha256sum' | sed 's/^\.\///'); do
225+
otp_version=$(echo "${sha256_file}" | sed -r 's/^elixir-otp-([[:digit:]]+)\.zip\.sha256sum/otp-\1/')
226+
build_sha256=$(cut -d ' ' -f 1 "${sha256_file}")
227+
228+
sed -i "/^${ref_name}-${otp_version} /d" builds.txt
229+
echo -e "${ref_name}-${otp_version} ${{ github.sha }} ${date} ${build_sha256} \n$(cat builds.txt)" > builds.txt
230+
231+
if [ "${otp_version}" == "otp-${OTP_GENERIC_VERSION}" ]; then
232+
sed -i "/^${ref_name} /d" builds.txt
233+
echo -e "${ref_name} ${{ github.sha }} ${date} ${build_sha256} \n$(cat builds.txt)" > builds.txt
234+
fi
235+
done
236+
237+
sort -u -k1,1 -o builds.txt builds.txt
238+
aws s3 cp builds.txt "s3://${AWS_S3_BUCKET}/builds/elixir/builds.txt" \
239+
--cache-control "public,max-age=3600" \
240+
--metadata '{"surrogate-key":"builds builds/elixir builds/elixir/txt","surrogate-control":"public,max-age=604800"}'
241+
242+
echo 'builds/elixir/txt' >> purge_keys.txt
243+
244+
- name: Flush cache
245+
if: github.repository == 'elixir-lang/elixir'
246+
run: |
247+
function purge_key() {
248+
curl \
249+
-X POST \
250+
-H "Fastly-Key: ${FASTLY_KEY}" \
251+
-H "Accept: application/json" \
252+
-H "Content-Length: 0" \
253+
"https://api.fastly.com/service/$1/purge/$2"
254+
}
255+
256+
function purge() {
257+
purge_key ${FASTLY_REPO_SERVICE_ID} $1
258+
purge_key ${FASTLY_BUILDS_SERVICE_ID} $1
259+
sleep 2
260+
purge_key ${FASTLY_REPO_SERVICE_ID} $1
261+
purge_key ${FASTLY_BUILDS_SERVICE_ID} $1
262+
sleep 2
263+
purge_key ${FASTLY_REPO_SERVICE_ID} $1
264+
purge_key ${FASTLY_BUILDS_SERVICE_ID} $1
265+
}
266+
267+
for key in $(cat purge_keys.txt); do
268+
purge "${key}"
269+
done

0 commit comments

Comments
 (0)