action-hosting-deploy
action-hosting-deploy copied to clipboard
Delete preview channel on close/merge
When a PR is merged or closed, is it possible to detect this and delete the associated preview channel?
I have set the expiry date to 30 days which isn't a problem but when dependabot or renovate decides it's time for 20 PRs then that's a lot of temporary channels being created. There is a limit of 50 preview channels in firebase (I think) and trying to add more fails with a 429
. I set the expiry date to 30 days under the assumption that if I left the PR long enough the channel would expire and it wouldn't be able to redeploy a new one? Correct me if I'm wrong. Firebase also seems to have issues deleting expired channels as they sit there "pending" for a day or so before going.
This seems like a reasonable configuration option, but just as an FYI -- the expiration date resets with each new deploy, so if you have a branch that is under active development you might safely choose a shorter expiration. So long as you push one new commit within the window, the clock resets.
just as an FYI -- the expiration date resets with each new deploy, so if you have a branch that is under active development you might safely choose a shorter expiration. So long as you push one new commit within the window, the clock resets.
Oh perfect I didn't notice that it did this. I suppose it does make sense for that to happen.
@mbleigh Does that mean we should be expecting this config to be added in the future?
Is anyone working on this? If not, I'll give it a shot. It'll be my first open-source contribution, so not sure if I can handle it. I really want this feature though haha.
It's been a few years but huge +1 to this feature. My team has 12 developers and we keep running out of preview channels. If we set the expiration to be too short (1 day, etc) they're not available when we need them. If we set it to be too long (7d) then we run out all the time.
This would help clean up stale ones. I don't think we ever actually have 50 live PRs.
As we know we need to mark them for deletion manually. Has anyone wrote a github action that marks the preview to expire "now" so that it at least does not live for longer than needed? Is this possible?
Edit: This one does the trick currently
name: Delete Firebase Hosting preview channel
on:
pull_request:
types: [closed]
jobs:
delete_preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: ⚙️ Setup Firebase CLI
uses: w9jds/[email protected]
env:
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_FRONTEND_B972E }}'
with:
# Extracts the full channel name from the PR number and feeds it to the delete command
args: hosting:channel:list | grep 'pr${{ github.event.pull_request.number }}' | cut --delimeter ' ' --fields 2 | xargs -I {} firebase hosting:channel:delete --force {}
^ the command above doesn't work for me but this does.
hosting:channel:list --site=<site-target> | awk -v pr_number="pr${{ github.event.pull_request.number }}" '$0 ~ pr_number { print $2 }' | xargs -I {} firebase hosting:channel:delete --site=<site-target> {} --force
It seems like the channel delete action actually takes the branch reference directly. We've been using this to delete for over a year now and doesn't need the advanced tricks:
.github/workflows/delete-firebase-channel.yml
name: Close PR delete firebase channel
on:
pull_request:
types: [closed]
jobs:
delete_firebase_channel:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: w9jds/[email protected]
with:
args: hosting:channel:delete ${{ github.head_ref }} --force
env:
GCP_SA_KEY: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_STAGING }}
PROJECT_ID: staging