Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .github/scripts/cleanup-gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ const FS = require('fs');

const TAG = 'cleanup-gh-pages:';

// Directories that should never be removed by cleanup
const PROTECTED_DIRS = ['main'];

const removeOldFromPath = (isTag, data) => {
const path = `public/${isTag ? 'version' : 'review'}`;
if (FS.existsSync(path) && data?.length > 0) {
const dataNames = data.map((item) => item.name);
const dirsToDelete = FS.readdirSync(path).filter(
(file) => !data.find((branch) => branch.name === file)
(file) => !PROTECTED_DIRS.includes(file) && !dataNames.includes(file)
);
if (dirsToDelete?.length > 0) {
console.log(
Expand All @@ -35,18 +39,20 @@ const removeOldFromPath = (isTag, data) => {

module.exports = async ({ github, context }) => {
const { repo, owner } = context.repo;
const branches = await github.rest.repos.listBranches({

// Use pagination to fetch all branches and tags
const branches = await github.paginate(github.rest.repos.listBranches, {
owner,
repo
repo,
per_page: 100
});
const tags = await github.rest.repos.listTags({
const tags = await github.paginate(github.rest.repos.listTags, {
owner,
repo
repo,
per_page: 100
});

return {
deploy:
removeOldFromPath(false, branches.data) ||
removeOldFromPath(true, tags.data)
deploy: removeOldFromPath(false, branches) || removeOldFromPath(true, tags)
};
};
1 change: 1 addition & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
return await script({github, context})

- name: 🥅 Deploy to GH-Pages
if: fromJSON(steps.cleanup.outputs.result).deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Loading