-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Cleans all preview pages for gh-pages | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
clean: | ||
name: Clean | ||
runs-on: ubuntu-24.04 # Use Ubuntu 24.04 explicitly | ||
steps: | ||
- name: ⏬ Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: 📥 Get gh-pages tar | ||
run: wget -q https://github.com/db-ux-design-system/theme-builder/tarball/gh-pages | ||
|
||
- name: ➕ Create dist dir | ||
run: mkdir dist | ||
|
||
- name: 📦 Unpack Tar | ||
run: tar -zxf gh-pages -C dist --strip-components 1 | ||
|
||
- name: 🗑️ Clean all preview pages | ||
id: cleanup | ||
uses: actions/github-script@v7 | ||
with: | ||
result-encoding: json | ||
script: | | ||
const { default: cleanUpPages } = await import('${{ github.workspace }}/scripts/cleanup-gh-pages.js'); | ||
return await cleanUpPages({github, context}); | ||
- name: 🥅 Deploy to GH-Pages | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Fetches all branches and deletes all review-branches in github pages | ||
*/ | ||
import FS from 'node:fs'; | ||
|
||
const TAG = 'cleanup-gh-pages:'; | ||
|
||
const removeOldFromPath = (isTag, data) => { | ||
const path = `public/${isTag ? 'version' : 'review'}`; | ||
if ( | ||
FS.existsSync(path) && | ||
data?.filter((branch) => branch.name).length > 0 | ||
) { | ||
const dirsToDelete = FS.readdirSync(path) | ||
.filter((file) => !data.find((branch) => branch.name === file)) | ||
// Let's not clean up specific folders | ||
.filter((file) => !['main', 'latest'].includes(file)); | ||
if (dirsToDelete?.length > 0) { | ||
console.log( | ||
TAG, | ||
`Start removing ${isTag ? 'tags' : 'branches'} from gh-pages` | ||
); | ||
console.log(TAG, dirsToDelete); | ||
for (const dir of dirsToDelete) { | ||
FS.rmSync(`${path}/${dir}`, { | ||
recursive: true, | ||
force: true | ||
}); | ||
console.log(TAG, `deleted ${isTag ? 'tag' : 'branch'} ${dir}`); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
console.log(TAG, `All ${isTag ? 'tags' : 'branches'} are up to date`); | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
const cleanUpPages = async ({ github, context }) => { | ||
const { repo, owner } = context.repo; | ||
const branches = await github.rest.repos.listBranches({ | ||
owner, | ||
repo | ||
}); | ||
const tags = await github.rest.repos.listTags({ | ||
owner, | ||
repo | ||
}); | ||
|
||
return { | ||
deploy: | ||
removeOldFromPath(false, branches.data) || | ||
removeOldFromPath(true, tags.data) | ||
}; | ||
}; | ||
|
||
export default cleanUpPages; |