action-hosting-deploy icon indicating copy to clipboard operation
action-hosting-deploy copied to clipboard

Delete preview channel on close/merge

Open napei opened this issue 4 years ago • 8 comments

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.

napei avatar Dec 12 '20 02:12 napei

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.

mbleigh avatar Dec 14 '20 17:12 mbleigh

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.

napei avatar Dec 16 '20 01:12 napei

@mbleigh Does that mean we should be expecting this config to be added in the future?

cybersokari avatar Dec 20 '20 10:12 cybersokari

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.

kozr avatar Dec 25 '20 05:12 kozr

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.

samatcolumn avatar Aug 02 '22 07:08 samatcolumn

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 {}

ollejernstrom avatar Aug 07 '23 12:08 ollejernstrom

^ 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

spedwin-lgtm avatar Aug 22 '23 02:08 spedwin-lgtm

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

odinho avatar Oct 13 '23 11:10 odinho