-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from MyAlbum/v2
V2
- Loading branch information
Showing
10 changed files
with
10,034 additions
and
53 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,49 @@ | ||
name: CI | ||
|
||
"on": | ||
push: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 0,12 * * *" | ||
|
||
jobs: | ||
build: | ||
name: Build app | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
# -------- THIS ACTION -------- | ||
- name: Purge caches | ||
uses: ./. | ||
with: | ||
debug: true | ||
# 3 days | ||
max-age: 259200 | ||
# -------- THIS ACTION -------- | ||
|
||
# http://man7.org/linux/man-pages/man1/date.1.html | ||
- name: Get Date | ||
id: get-date | ||
run: | | ||
echo "date=$(/bin/date -u "+date-%Y-%m-%d-time-%H-%M-%S")" >> $GITHUB_OUTPUT | ||
shell: bash | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.npm | ||
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json', 'package.json') }}-${{ steps.get-date.outputs.date }} | ||
restore-keys: | | ||
${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json', 'package.json') }}- | ||
- name: Install packages and build the app | ||
run: npm ci | ||
- name: Commit & Push changes | ||
run: | | ||
git config --global user.name github-actions | ||
git config --global user.email [email protected] | ||
git pull --rebase --autostash | ||
git add dist | ||
git commit -m "action: build the app" || echo "" | ||
git push |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
lib |
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,67 @@ | ||
import * as github from '@actions/github'; | ||
import * as core from '@actions/core'; | ||
|
||
async function run() { | ||
const debug = core.getInput('debug', { required: false }) === 'true'; | ||
const maxAge = core.getInput('max-age', { required: true }); | ||
const token = core.getInput('token', { required: false }); | ||
const octokit = github.getOctokit(token); | ||
const maxDate = new Date(Date.now() - Number.parseInt(maxAge) * 1000) | ||
|
||
interface Cache { | ||
id?: number | undefined; | ||
ref?: string | undefined; | ||
key?: string | undefined; | ||
version?: string | undefined; | ||
last_accessed_at?: string | undefined; | ||
created_at?: string | undefined; | ||
size_in_bytes?: number | undefined; | ||
} | ||
|
||
const results: Cache[] = [] | ||
|
||
for (let i = 1; i <= 100; i += 1) { | ||
const { data: cachesRequest } = await octokit.rest.actions.getActionsCacheList({ | ||
owner: github.context.repo.owner, | ||
repo: github.context.repo.repo, | ||
per_page: 100, | ||
page: i | ||
}); | ||
|
||
if (cachesRequest.actions_caches.length == 0) { | ||
break | ||
} | ||
|
||
results.push(...cachesRequest.actions_caches) | ||
} | ||
|
||
if (debug) { | ||
console.log(`Found ${results.length} caches`); | ||
} | ||
|
||
results.forEach(async (cache) => { | ||
if (cache.last_accessed_at !== undefined && cache.id !== undefined) { | ||
const cacheDate = new Date(cache.last_accessed_at); | ||
if (cacheDate < maxDate) { | ||
if (debug) { | ||
console.log(`Deleting cache ${cache.key}, last accessed at ${cacheDate} before ${maxDate}`); | ||
} | ||
|
||
try { | ||
await octokit.rest.actions.deleteActionsCacheById({ | ||
per_page: 100, | ||
owner: github.context.repo.owner, | ||
repo: github.context.repo.repo, | ||
cache_id: cache.id, | ||
}); | ||
} catch (error) { | ||
console.log(`Failed to delete cache ${cache.key}; ${error}`); | ||
} | ||
} else if (debug) { | ||
console.log(`Skipping cache ${cache.key}, last accessed at ${cacheDate} after ${maxDate}`); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
run(); |
Oops, something went wrong.