Skip to content

[Language Badge, Language Badge Group]: Check for 1.2 release #272

[Language Badge, Language Badge Group]: Check for 1.2 release

[Language Badge, Language Badge Group]: Check for 1.2 release #272

# When a pull request is closed (merged or not), remove the associated Storybook deployment folder
# from `gh-pages` branch and mark its deployment environment as inactive. This is necessary to
# maintaing the GH Pages deployment size under 1 GB and to avoid accumulating active environments
# in GitHub (with broken links).
name: Remove old Storybook deployments
on:
pull_request:
types:
- closed
jobs:
remove-storybook:
name: Remove Storybook folder and update deployment status
runs-on: ubuntu-22.04
permissions:
contents: write
deployments: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: gh-pages
- name: Setup user
uses: fregante/setup-git-user@v2
- name: Read deployment ID from commit
id: parse-commit
# TODO: Add regex filtering to the `git log` command so this wouldn't fail if it encounters a merge commit.
run: MSG=$(git --no-pager log -n 1 --pretty=format:%s ${{ github.event.pull_request.head.ref }}) && echo "deployment_id=${MSG%%/*}" >> $GITHUB_OUTPUT
- name: Remove branch folder and commit changes
run: |
rm -rf ${{ github.event.pull_request.head.ref }}
git add .
git commit -m "removed ${{ github.event.pull_request.head.ref }}"
git push
- name: Mark deployment as inactive
if: steps.parse-commit.outputs.deployment_id != ''
uses: octokit/request-action@v2.1.7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
route: POST /repos/${{ github.repository }}/deployments/{deployment_id}/statuses
deployment_id: ${{ steps.parse-commit.outputs.deployment_id }}
state: inactive