Skip to content

fix clean up script #79

fix clean up script

fix clean up script #79

Workflow file for this run

name: Package Clean Up
on:
pull_request:
types: [closed]
jobs:
preview-clean-up:
name: "Clean Up Preview deployments"
runs-on: "ubuntu-latest"
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: preview
- name: Setup Git
run: |
git config --global user.name "xLabs Playground CI"
git config --global user.email "devops@xlabs-playground.xyz"
- name: Set Version
run: echo "_BRANCH_NAME_SHA=$(echo ${{ github.event.pull_request.head.ref }} | sha256sum | cut -c -10)" >> "${GITHUB_ENV}"
- name: Unpublish and remove preview artifacts
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
clean_up() {
shopt -s extglob
INPUT=$(gh pr list --json headRefName --jq '.[].headRefName')
OUTPUT="clean.sh"
# Loop through the array and concatenate the strings with pipe character
for BRANCH in ${INPUT}; do
HASH=$(echo ${BRANCH} | sha256sum | cut -c -10)
if [ -n "${OUTPUT}" ]; then
OUTPUT="${OUTPUT}|${HASH}"
else
OUTPUT="${HASH}"
fi
done
echo "Hashes to remove ${OUTPUT}"
rm -rf !(${OUTPUT})
}
npm run unpublish ${_BRANCH_NAME_SHA}
cd preview
clean_up
git add .
git commit -m"Remove preview artifacts"
git push
testnet-clean-up:
name: "Clean Up Testnet deployments"
runs-on: "ubuntu-latest"
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: testnet
- name: Setup Git
run: |
git config --global user.name "xLabs Playground CI"
git config --global user.email "devops@xlabs-playground.xyz"
- name: Compute Version
run: |
echo "_BRANCH_NAME_SHA=$(echo ${{ github.event.pull_request.head.ref }} | sha256sum | cut -c -10)" >> "${GITHUB_ENV}"
- name: Unpublish and remove testnet artifacts
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
clean_up() {
shopt -s extglob
INPUT=$(gh pr list --json headRefName --jq '.[].headRefName')
OUTPUT="clean.sh"
# Loop through the array and concatenate the strings with pipe character
for BRANCH in ${INPUT}; do
HASH=$(echo ${BRANCH} | sha256sum | cut -c -10)
if [ -n "${OUTPUT}" ]; then
OUTPUT="${OUTPUT}|${HASH}"
else
OUTPUT="${HASH}"
fi
done
echo "Hashes to remove ${OUTPUT}"
rm -rf !(${OUTPUT})
}
npm run unpublish ${_BRANCH_NAME_SHA}
cd testnet
clean_up
git add .
git commit -m"Remove testnet artifacts"
git push