Skip to content

Commit b9bcfae

Browse files
authored
Publish precompiled to s3 on releasing (#12242)
1 parent ad332ec commit b9bcfae

File tree

1 file changed

+61
-14
lines changed

1 file changed

+61
-14
lines changed

.github/workflows/repo.hex.pm.yml

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches:
66
- main
77
- v*.*
8+
tags:
9+
- v*
810

911
env:
1012
ELIXIR_OPTS: "--warnings-as-errors"
@@ -19,10 +21,12 @@ jobs:
1921
include:
2022
- otp: 24
2123
otp_version: 24.3
24+
upload_generic_version: upload_generic_version
2225
- otp: 25
2326
otp_version: 25.0
2427
build_docs: build_docs
2528
runs-on: ubuntu-20.04
29+
concurrency: builds_txt
2630
steps:
2731
- uses: actions/checkout@v3
2832
with:
@@ -32,6 +36,26 @@ jobs:
3236
otp_version: ${{ matrix.otp_version }}
3337
otp: ${{ matrix.otp }}
3438
build_docs: ${{ matrix.build_docs }}
39+
- name: Utils.sh
40+
run: |
41+
cat << EOF > utils.sh
42+
function purge_key() {
43+
curl \
44+
-X POST \
45+
-H "Fastly-Key: ${FASTLY_KEY}" \
46+
-H "Accept: application/json" \
47+
-H "Content-Length: 0" \
48+
"https://api.fastly.com/service/${FASTLY_SERVICE_ID}/purge/$1"
49+
}
50+
function purge() {
51+
purge_key $1
52+
sleep 2
53+
purge_key $1
54+
sleep 2
55+
purge_key $1
56+
}
57+
EOF
58+
chmod +x utils.sh
3559
- name: Upload Docs to S3
3660
if: ${{ matrix.build_docs }}
3761
env:
@@ -42,15 +66,7 @@ jobs:
4266
FASTLY_SERVICE_ID: ${{ secrets.HEX_FASTLY_SERVICE_ID }}
4367
FASTLY_KEY: ${{ secrets.HEX_FASTLY_KEY }}
4468
run: |
45-
function purge_key() {
46-
curl \
47-
-X POST \
48-
-H "Fastly-Key: ${FASTLY_KEY}" \
49-
-H "Accept: application/json" \
50-
-H "Content-Length: 0" \
51-
"https://api.fastly.com/service/${FASTLY_SERVICE_ID}/purge/$1"
52-
}
53-
69+
source utils.sh
5470
version=$(echo ${{ github.ref_name }} | sed -e 's/^v//g')
5571
for f in doc/*; do
5672
if [ -d "$f" ]; then
@@ -61,10 +77,41 @@ jobs:
6177
aws s3 cp "${tarball}" "s3://${{ env.AWS_S3_BUCKET }}/docs/${tarball}" \
6278
--cache-control "public,max-age=3600" \
6379
--metadata "{\"surrogate-key\":\"${surrogate_key}\",\"surrogate-control\":\"public,max-age=604800\"}"
64-
purge_key "${surrogate_key}"
65-
sleep 2
66-
purge_key "${surrogate_key}"
67-
sleep 2
68-
purge_key "${surrogate_key}"
80+
purge "${surrogate_key}"
6981
fi
7082
done
83+
- name: Upload Precompiled to S3
84+
env:
85+
AWS_ACCESS_KEY_ID: ${{ secrets.HEX_AWS_ACCESS_KEY_ID }}
86+
AWS_SECRET_ACCESS_KEY: ${{ secrets.HEX_AWS_SECRET_ACCESS_KEY }}
87+
AWS_REGION: ${{ secrets.HEX_AWS_REGION }}
88+
AWS_S3_BUCKET: ${{ secrets.HEX_AWS_S3_BUCKET }}
89+
run: |
90+
aws s3 cp elixir-otp-${{ matrix.otp }}.zip "s3://${{ env.AWS_S3_BUCKET }}/builds/elixir/${{github.ref_name}}-otp-${{matrix.otp}}.zip" --cache-control "public,max-age=3600" --metadata '{"surrogate-key":"builds","surrogate-control":"public,max-age=604800"}'
91+
if [ "${{matrix.upload_generic_version}}" == "upload_generic_version" ]; then
92+
aws s3 cp elixir-otp-${{ matrix.otp }}.zip "s3://${{ env.AWS_S3_BUCKET }}/builds/elixir/${{github.ref_name}}.zip" --cache-control "public,max-age=3600" --metadata '{"surrogate-key":"builds","surrogate-control":"public,max-age=604800"}'
93+
fi
94+
- name: Update builds txt
95+
env:
96+
AWS_ACCESS_KEY_ID: ${{ secrets.HEX_AWS_ACCESS_KEY_ID }}
97+
AWS_SECRET_ACCESS_KEY: ${{ secrets.HEX_AWS_SECRET_ACCESS_KEY }}
98+
AWS_REGION: ${{ secrets.HEX_AWS_REGION }}
99+
AWS_S3_BUCKET: ${{ secrets.HEX_AWS_S3_BUCKET }}
100+
FASTLY_SERVICE_ID: ${{ secrets.HEX_FASTLY_SERVICE_ID }}
101+
FASTLY_KEY: ${{ secrets.HEX_FASTLY_KEY }}
102+
run: |
103+
source utils.sh
104+
date=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
105+
build_sha256=$(sha256sum elixir-otp-${{ matrix.otp }}.zip | cut -d ' ' -f 1)
106+
ref_name=${{ github.ref_name }}
107+
aws s3 cp s3://${{ env.AWS_S3_BUCKET }}/builds/elixir/builds.txt builds.txt || true
108+
touch builds.txt
109+
sed -i "/^${ref_name}-otp-${{ matrix.otp }} /d" builds.txt
110+
echo -e "${ref_name}-otp-${{ matrix.otp }} ${{ github.sha }} ${date} ${build_sha256} \n$(cat builds.txt)" > builds.txt
111+
if [ "${{matrix.upload_generic_version}}" == "upload_generic_version" ]; then
112+
sed -i "/^${ref_name} /d" builds.txt
113+
echo -e "${ref_name} ${{ github.sha }} ${date} ${build_sha256} \n$(cat builds.txt)" > builds.txt
114+
fi
115+
sort -u -k1,1 -o builds.txt builds.txt
116+
aws s3 cp builds.txt s3://${{ env.AWS_S3_BUCKET }}/builds/elixir/builds.txt --cache-control "public,max-age=3600" --metadata '{"surrogate-key":"builds","surrogate-control":"public,max-age=604800"}'
117+
purge builds

0 commit comments

Comments
 (0)