#22 delete preview on close

This commit is contained in:
neil 2022-11-24 11:06:02 +08:00
parent 9ef9febc61
commit f74a81e79d
3 changed files with 74 additions and 0 deletions

37
.github/remove-distribution.sh vendored Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
rm ./test.json
rm ./final.json
prefix=$1
echo $(aws cloudfront list-distributions --output json) >> ./test.json
data=$(cat ./test.json)
distribution_id="NONE"
for row in $(jq '.DistributionList.Items[] | @base64' < './test.json'); do
_jq() {
echo $row | tr -d '"' | base64 --decode | jq -r "${1}" | tr -d '"'
}
comment=$(_jq '.Comment')
if [[ $comment = $prefix ]]
then
distribution_id=$(_jq '.Id')
fi
done
if [[ $distribution_id = NONE ]]
then
echo "distribution does not exist"
else
echo $distribution_id
config=$(aws cloudfront get-distribution-config --id $distribution_id)
echo $config | jq '.DistributionConfig' | jq '.Enabled = false' >> final.json
etag_get=$(aws cloudfront get-distribution --id $distribution_id | jq '.ETag' | tr -d '"')
do_nothing=$(aws cloudfront update-distribution --id $distribution_id --if-match $etag_get --distribution-config file://final.json)
echo "disabling distribution"
aws cloudfront wait distribution-deployed --id $distribution_id
echo "distribution disabled"
etag_delete=$(aws cloudfront get-distribution --id $distribution_id | jq '.ETag' | tr -d '"')
aws cloudfront delete-distribution --id $distribution_id --if-match $etag_delete
echo "done"
fi

35
.github/workflows/cleanup.yml vendored Normal file
View file

@ -0,0 +1,35 @@
on:
pull_request:
types:
- closed
jobs:
clean-up:
runs-on: ubuntu-latest
steps:
- name: inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
- name: get s3 preview folder
id: preview
run: |
preview=$(echo $GITHUB_REF_NAME | sed -e 's/\//-/g')
echo "folder=$preview" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: remove distribution preview
run: .github/remove-distribution.sh ${{ steps.preview.outputs.folder }}
# consider to rm the folder later, maybe someone might need to download the installer
# - name: remove s3 folder
# run: aws s3 rm s3://preview.gui.tea.xyz/ --recursive --exclude "*" --include "${{ steps.preview.outputs.folder }}/*"

View file

@ -30,3 +30,5 @@ You can preview the production build with `npm run preview`.
## Intuition Building Links ## Intuition Building Links
* [Rust module system is weird?](https://www.sheshbabu.com/posts/rust-module-system/) * [Rust module system is weird?](https://www.sheshbabu.com/posts/rust-module-system/)
TEST PREVIEW