Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prune-prereleases.js pruning rules #6806

Merged
merged 4 commits into from
Jan 16, 2024
Merged

Commits on Jan 15, 2024

  1. Update prune-prereleases.js pruning rules

        // Pruning rules:
        //   1. only keep the earliest release of the month
        //   2. to keep the newest 3 nightlies
    
    ```
    import { Octokit, App } from "octokit";
    
    // Create a personal access token at https://github.com/settings/tokens/new?scopes=repo
    const octokit = new Octokit({ });
    
    // In case node 21 is not used.
    function groupBy(array, keyOrIterator) {
        var iterator;
    
        // use the function passed in, or create one
        if(typeof keyOrIterator !== 'function') {
            const key = String(keyOrIterator);
            iterator = function (item) { return item[key]; };
        } else {
            iterator = keyOrIterator;
        }
    
        return array.reduce(function (memo, item) {
            const key = iterator(item);
            memo[key] = memo[key] || [];
            memo[key].push(item);
            return memo;
        }, {});
    }
    
    async function separateReleases({ github, context }) {
        console.log("Pruning old prereleases");
    
        // doc: https://docs.github.com/en/rest/releases/releases
        const { data: releases } = await github.rest.repos.listReleases({
            owner: context.repo.owner,
            repo: context.repo.repo,
        });
    
        let nightlies = releases.filter(
            release =>
            // Only consider releases tagged `nightly-${SHA}` for deletion
            release.tag_name.includes("nightly") &&
            release.tag_name !== "nightly"
        );
    
        // group releases by months
        const groups = groupBy(nightlies, i => i.created_at.slice(0, 7));
    
        // Pruning rules:
        //   1. only keep the earliest release of the month
        //   2. to keep the newest 3 nightlies
        const toPrune = Object.values(groups)
            .reduce((acc, cur) => acc.concat(cur.slice(0, -1)), [])
            .slice(3);
    
        const toKeep = Object.values(groups).reduce((acc, cur) => acc.concat(cur.slice(-1)), []);
    
        return {
            toPrune,
            toKeep,
        };
    };
    
    (async() => {
        const releases = await separateReleases({
            github : octokit,
            context : {
                repo : { owner: "foundry-rs", repo: "foundry" }
            },
        });
        console.log("To prune:", releases.toPrune.map(i => i.name));
        console.log("To keep:", releases.toKeep.map(i => i.name));
    })();
    ```
    
    ```
    $ node index.mjs 
    Pruning old prereleases
    To prune: [ 'Nightly (2023-11-01)' ]
    To keep: [
      'Nightly (2024-01-12)',
      'Nightly (2023-12-02)',
      'Nightly (2023-11-02)',
      'Nightly (2023-10-02)',
      'Nightly (2023-08-02)',
      'Nightly (2023-07-02)',
      'Nightly (2023-06-02)',
      'Nightly (2023-05-02)',
      'Nightly (2023-04-02)',
      'Nightly (2023-03-02)',
      'Nightly (2023-01-03)'
    ]
    ```
    hellwolf authored Jan 15, 2024
    Configuration menu
    Copy the full SHA
    9c7e90a View commit details
    Browse the repository at this point in the history
  2. Update prune-prereleases.js

    hellwolf authored Jan 15, 2024
    Configuration menu
    Copy the full SHA
    4deaaae View commit details
    Browse the repository at this point in the history

Commits on Jan 16, 2024

  1. Update prune-prereleases.js

    hellwolf authored Jan 16, 2024
    Configuration menu
    Copy the full SHA
    2f27753 View commit details
    Browse the repository at this point in the history
  2. Update prune-prereleases.js

    hellwolf authored Jan 16, 2024
    Configuration menu
    Copy the full SHA
    8e38ef1 View commit details
    Browse the repository at this point in the history