38
votes

Every time you deploy to Firebase hosting a new deploy version is created so you can roll back and see who deployed. This means that each time every file you deploy is stored and occupying more space.

Other than manually deleting each deployed version one by one, is there any automated way to clean those useless files?

8
This is now the answer as of March 2019: stackoverflow.com/a/47213789/1271706Dylan Watson

8 Answers

30
votes

You're correct. You'll need to delete the old deployed versions one by one using the Firebase Hosting console.

There's no other way to do this, so I'd suggest you to file a feature request to enable deletion of multiple deployed version in the Firebase Hosting console.

Update:

You can vote here (please avoid +1 spam, use reactions) https://github.com/firebase/firebase-tools/issues/215#issuecomment-314211730 for one of the alternatives proposed by the team (batch delete, keep only X versions, keep versions with published date < Y)

19
votes

UPDATE Mar/2019

There's now a proper solution: "Version history settings" which allows to keep the last X versions.

https://support.google.com/firebase/answer/9242086?hl=en


UPDATE Feb/2019

Confirmed by Google employee @ github.com/firebase/firebase-tools/issues/...

It is actively being worked on. 🙂

🎉🎉🎉


Before continuing reading:

You can vote here (please avoid +1 spamming, use reactions) https://github.com/firebase/firebase-tools/issues/215#issuecomment-314211730 for one of the alternatives proposed by the team


So, by using Chrome Dev tools I found a way to delete multiple versions. Keep in mind it requires a bit for work (proceed with care since deleted versions can't be restored and you won't get any warnings like when using the UI).

Step 1. Retrieving the version list.

  1. Open Chrome Dev Tools (if you don't know how to chances are you should wait for a proper solution by Firebase's team).
  2. Open Firebase's Console and go to the "Hosting" tab.
  3. Go to the "Network" tab on CDT and use the Websockets filter.
  4. Select the request named .ws?v=5&ns=firebase
  5. Open the "Frames" tab
  6. Now comes the tedious part: Select the frames with the highest "length" value. (Depending on your data, it could be 2-n frames. In my case, 3 frames with 14k-16k length)
  7. Paste each of the frame's data in order (which will form a valid JSON object).
  8. Extracting the data: There are several ways to do it. I opted for simple JS on CDT's console.
    var jsonString = '...';
    var json = JSON.parse(jsonString);
    var ids = Object.keys(json.d.b.d);

Step 2. Performing the requests

Almost there :P

Now that you have the IDs, perform the following requests:

DELETE https://firebasehosting.clients6.google.com/v1beta1/sites/PROJECT_NAME/versions/-VERSION_ID?key=KEY

I used Sublime (to create the request strings) + Paw.

The "KEY" can be copied from any of CDT's requests. It doesn't match Firebase's Web API key

=> Before performing the requests: take note of the version you don't want to delete from the table provided by Firebase. (Each version listed on the website has the last 6 digits of it's ID under your email)

(Screenshots weren't provided since all of them would require blurring and a bit of work)

15
votes

This script is not yet super-solid, so use it at your own risk. I'll try to update it later, but worked for me for now. Just some javascript to click on buttons to delete deployed items one by one.

var deleteDeployment = function(it) {
    it.click()
    setTimeout(function() {
        $('.md-dialog-container .delete-dialog button.md-raised:contains("Delete")').click()
    }, 300)
}
$('.h5g-hist-status-deployed').map((i, a) => $(a).parent()).map((i, a) => $(a).find('md-menu button:contains(Delete)')).each((i, it) => {
    setTimeout(function() {
        deleteDeployment(it)
    }, (i + 1) * 2000)
})
4
votes

Firebase finally implemented a solution for this.

It is now possible to set a limit of retained versions.

https://firebase.google.com/docs/hosting/deploying#set_limit_for_retained_versions

EDIT: previous link is outdated. Here is a new link that works:

https://firebase.google.com/docs/hosting/usage-quotas-pricing#control-storage-usage

2
votes

This may be a bit brittle due to the selectors' reliance on current DOM structure and classes on the Hosting Dashboard, but it works for me!

NOTE: This script (if executed from the console) or bookmarklet will click and confirm delete on all of the rows in the current view. I'm fairly certain that even if you click delete on the current deployment it will not delete it.

Function for running in console:

let deleteAllHistory = () => {
  let deleteBtns = document.querySelectorAll('.table-row-actions button.md-icon-button');

  const deleteBtn = (pointer) => {
        deleteBtns[pointer].click();

        setTimeout(() => {
          document.querySelector('.md-open-menu-container.md-clickable md-menu-item:last-child button').click();

          setTimeout(() => {
            document.querySelector('.fb-dialog-actions .md-raised').click();

            if(pointer < deleteBtns.length - 1) {
              deleteBtn(pointer + 1);
            }
          }, 500);
        }, 500);
  };

  deleteBtn(0);
};

Bookmarklet:

javascript:(function()%7Bvar%20deleteBtns%3Ddocument.querySelectorAll('.table-row-actions%20button.md-icon-button')%2CdeleteBtn%3Dfunction(a)%7BdeleteBtns%5Ba%5D.click()%2CsetTimeout(function()%7Bdocument.querySelector('.md-open-menu-container.md-clickable%20md-menu-item%3Alast-child%20button').click()%2CsetTimeout(function()%7Bdocument.querySelector('.fb-dialog-actions%20.md-raised').click()%2Ca%3CdeleteBtns.length-1%26%26deleteBtn(a%2B1)%7D%2C500)%7D%2C500)%7D%3BdeleteBtn(0)%7D)()
0
votes

Nathan's option is great, but I have a quick-and-dirty method using AutoHotkey. Takes about a second per version to delete, so you can knock out a page in 10 seconds.

#a::
    Click
    MouseGetPos, xpos, ypos
    MouseMove, xpos, ypos + 30
    Sleep 300
    Click
    Sleep 400
    Click 1456, 816
    MouseMove, xpos, ypos + 82
return
#s::
    Click
    MouseGetPos, xpos, ypos
    MouseMove, xpos, ypos - 820
return

You'll likely need to modify the exact pixel values for your screen, but this works perfectly on my 1920x1080.

Win + a is delete and move to the next entry, Win + s is move to the next page. Put your mouse on the first 3-dot menu and go for it!

0
votes

On top of the release history table, click the tool bar and select "Version history settings". Set to desired amount and click save.This will auto delete older deployments.

-1
votes

I don't know it can help you or not but I can delete old deployments from "hosting" menu like this: Delete or rollback old deployment