Add a protected_files input that accepts a minimatch glob

This commit is contained in:
Bret Comnes 2021-01-17 13:55:02 -07:00
parent 15d3299d41
commit cadbbff700
No known key found for this signature in database
GPG Key ID: 3705F4634DC3A1AC
9 changed files with 1290 additions and 46 deletions

View File

@ -17,11 +17,9 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v2.1.4
with:
node-version: 12
- name: Install deps and build
run: |
npm i
npm run build
node-version: 15
- run: npm i
- run: npm run build
# When the dist_dir is ready, deploy it to neocities
- name: Deploy to neocities
uses: bcomnes/deploy-to-neocities@master # dont use master in production
@ -29,3 +27,4 @@ jobs:
api_token: ${{ secrets.NEOCITIES_API_TOKEN }}
cleanup: false
dist_dir: public
protected_files: 'dropbox/*'

View File

@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [12]
node: [15]
steps:
- uses: actions/checkout@v2
@ -17,10 +17,8 @@ jobs:
uses: actions/setup-node@v2.1.4
with:
node-version: ${{ matrix.node }}
- name: npm install && npm test
run: |
npm i
npm test
- run: npm i
- run: npm test
automerge:
needs: test

17
.vscode/launch.json vendored
View File

@ -1,17 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/test.js"
}
]
}

View File

@ -7,7 +7,7 @@
<center><img src="static/logo.png"></center>
Efficiently deploy a website to [Neocities][nc] using [Github actions](https://github.com/features/actions). Uses content aware diffing to only update files that changed.
Efficiently deploy a website to [Neocities][nc] using [Github actions](https://github.com/features/actions). Uses content aware diffing to only update files that changed.
## Usage
@ -69,6 +69,7 @@ You most likely only want to run this on the `master` branch so that only change
- `api_token` (**REQUIRED**): The API token for your [Neocities][nc] website to deploy to.
- `dist_dir`: The directory to deploy to [Neocities][nc]. Default: `public`.
- `cleanup`: Boolean string (`true` or `false`). If `true`, `deploy-to-neocities` will destructively delete files found on [Neocities][nc] not found in your `dist_dir`. Default: `false`.
- `protected_files`: An optional glob string used to mark files as protected. Protected files are never cleaned up. Test this option out with `cleanup` set to false before relying on it. Protected files are printed when `cleanup` is set to true or false. Glob strings are processed by [minimatch](https://github.com/isaacs/minimatch) against remote neocities file paths. Protected files can still be updated.
### Outputs

View File

@ -15,6 +15,9 @@ inputs:
description: Delete orphaned files on neocities that don't exist in distDir
default: false
required: true
protected_files:
description: A glob string that prevents matched files from ever being deleted.
required: false
runs:
using: 'node12'
main: 'dist/index.js'

1277
dist/index.js vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,7 @@ const path = require('path')
const ms = require('ms')
const assert = require('webassert').default
const fsp = require('fs').promises
const minimatch = require('minimatch')
let cleanup
@ -12,6 +13,7 @@ async function doDeploy () {
const token = core.getInput('api_token')
const distDir = path.join(process.cwd(), core.getInput('dist_dir'))
cleanup = JSON.parse(core.getInput('cleanup'))
const protectedFilesGlob = core.getInput('protected_files')
assert(typeof cleanup === 'boolean', 'Cleanup input must be a boolean "true" or "false"')
const stat = await fsp.stat(distDir)
@ -19,15 +21,23 @@ async function doDeploy () {
const client = new Neocities(token)
const stats = await client.deploy(distDir, {
const deployOpts = {
cleanup,
statsCb: Neocities.statsHandler()
})
}
if (protectedFilesGlob) deployOpts.protectedFileFilter = minimatch.filter(protectedFilesGlob)
const stats = await client.deploy(distDir, deployOpts)
console.log(`Deployed to Neocities in ${ms(stats.time)}:`)
console.log(` Uploaded ${stats.filesToUpload.length} files`)
console.log(` ${cleanup ? 'Deleted' : 'Orphaned'} ${stats.filesToDelete.length} files`)
console.log(` Skipped ${stats.filesSkipped.length} files`)
console.log(` ${stats.protectedFiles.length} protected files:`)
if (stats.protectedFiles.length) {
console.log(stats.protectedFiles)
}
}
doDeploy().catch(err => {

View File

@ -8,7 +8,8 @@
},
"dependencies": {
"@actions/core": "1.2.6",
"async-neocities": "2.0.2",
"async-neocities": "2.1.1",
"minimatch": "^3.0.4",
"ms": "2.1.3",
"webassert": "3.0.2"
},