diff --git a/README.md b/README.md index 181f98be2..269972c51 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ Note that the `GITHUB_TOKEN` that is created by the runner might not inherently - [⭐️ Set Git username and email](#%EF%B8%8F-set-git-username-and-email) - [⭐️ Set custom commit message](#%EF%B8%8F-set-custom-commit-message) - [⭐️ Create Git tag](#%EF%B8%8F-create-git-tag) + - [⭐️ Clean up a working directory `cleanup_work_dir`](#%EF%B8%8F-clean-up-a-working-directory-cleanup_work_dir) - [Tips and FAQ](#tips-and-faq) - [⭐️ Create SSH Deploy Key](#%EF%B8%8F-create-ssh-deploy-key) - [⭐️ First Deployment with `GITHUB_TOKEN`](#%EF%B8%8F-first-deployment-with-github_token) @@ -529,6 +530,19 @@ deploy-v1.2.3 # Tag on the gh-pages branch v1.2.3 # Tag on the main branch ``` +### ⭐️ Clean up a working directory `cleanup_work_dir` +We can set the `cleanup_work_dir: true` option. +This allows you to delete a working directory (`$HOME/actions_github_pages_{unixTime}`). + +```yaml +- name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./public + cleanup_work_dir: true +``` +
diff --git a/__tests__/get-inputs.test.ts b/__tests__/get-inputs.test.ts index 2cd306a9d..2f2faa820 100644 --- a/__tests__/get-inputs.test.ts +++ b/__tests__/get-inputs.test.ts @@ -56,6 +56,7 @@ function getInputsLog(authMethod: string, inps: Inputs): string { [INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll} [INFO] CNAME: ${inps.CNAME} [INFO] ExcludeAssets ${inps.ExcludeAssets} +[INFO] CleanupWorkDir: ${inps.CleanupWorkDir} `; } @@ -125,6 +126,7 @@ describe('getInputs()', () => { expect(inps.DisableNoJekyll).toBe(false); expect(inps.CNAME).toMatch(''); expect(inps.ExcludeAssets).toMatch('.github'); + expect(inps.CleanupWorkDir).toBe(false); }); test('get spec inputs', () => { @@ -147,6 +149,7 @@ describe('getInputs()', () => { process.env['INPUT_DISABLE_NOJEKYLL'] = 'true'; process.env['INPUT_CNAME'] = 'github.com'; process.env['INPUT_EXCLUDE_ASSETS'] = '.github'; + process.env['INPUT_CLEANUP_WORK_DIR'] = 'false'; const inps: Inputs = getInputs(); @@ -169,6 +172,7 @@ describe('getInputs()', () => { expect(inps.DisableNoJekyll).toBe(true); expect(inps.CNAME).toMatch('github.com'); expect(inps.ExcludeAssets).toMatch('.github'); + expect(inps.CleanupWorkDir).toBe(false); }); test('get spec inputs enable_jekyll', () => { @@ -184,6 +188,6 @@ describe('getInputs()', () => { expect(() => { getInputs(); - }).toThrowError('Use either of enable_jekyll or disable_nojekyll'); + }).toThrow('Use either of enable_jekyll or disable_nojekyll'); }); }); diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 31eaefc0a..802d57555 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -4,6 +4,7 @@ import { getHomeDir, getWorkDirName, createDir, + deleteDir, addNoJekyll, addCNAME, skipOnFork @@ -61,6 +62,17 @@ describe('createDir()', () => { }); }); +describe('deleteDir()', () => { + test('delete a directory', async () => { + const unixTime = await getTime(); + const workDirName = await getWorkDirName(`${unixTime}`); + await createDir(workDirName); + await deleteDir(workDirName); + const test = fs.existsSync(workDirName); + expect(test).toBe(false); + }); +}); + async function getWorkDir(): Promise