mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2025-06-18 01:55:29 +08:00
Compare commits
4 Commits
d0fa327ac7
...
f32618c774
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f32618c774 | ||
![]() |
288264f9c9 | ||
![]() |
28797ce1ee | ||
![]() |
cef7a7b43d |
20
README.md
20
README.md
@ -151,13 +151,27 @@ This action fetches the latest version of Hugo by [hugo | Homebrew Formulae](htt
|
|||||||
### ⭐️ Caching Hugo Modules
|
### ⭐️ Caching Hugo Modules
|
||||||
|
|
||||||
Insert a cache step before site-building as follows.
|
Insert a cache step before site-building as follows.
|
||||||
Note that with latest hugo version, the [cache dir location](https://gohugo.io/getting-started/configuration/#configure-cachedir) on a Linux-based operating system is `${HOME}/.cache`. On macOS, `${HOME}/Library/Caches` has the location.
|
|
||||||
|
First, to maximize compatibility with all Hugo versions, let's define the variable `HUGO_CACHEDIR`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# * ...
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
env:
|
||||||
|
HUGO_CACHEDIR: /tmp/hugo_cache # <- Define the env variable here, so that Hugo's cache dir is now predictible in your workflow and doesn't depend on the Hugo's version you're using.
|
||||||
|
|
||||||
|
# * ...
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, let's add the cache action call just above the _Build_ step:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: /home/runner/.cache/hugo_cache # <-- with hugo version v0.116.0 and above
|
path: ${{ env.HUGO_CACHEDIR }} # <- Use the same env variable just right here
|
||||||
# path: /tmp/hugo_cache # <-- with hugo version < v0.116.0
|
|
||||||
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-hugomod-
|
${{ runner.os }}-hugomod-
|
||||||
|
@ -25,6 +25,7 @@ describe('Integration testing run()', () => {
|
|||||||
test('succeed in installing a custom version', async () => {
|
test('succeed in installing a custom version', async () => {
|
||||||
const testVersion = Tool.TestVersionSpec;
|
const testVersion = Tool.TestVersionSpec;
|
||||||
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
||||||
|
process.env['INPUT_EXTENDED'] = 'false';
|
||||||
const result: main.ActionResult = await main.run();
|
const result: main.ActionResult = await main.run();
|
||||||
expect(result.exitcode).toBe(0);
|
expect(result.exitcode).toBe(0);
|
||||||
expect(result.output).toMatch(`hugo v${testVersion}`);
|
expect(result.output).toMatch(`hugo v${testVersion}`);
|
||||||
@ -43,6 +44,7 @@ describe('Integration testing run()', () => {
|
|||||||
test('succeed in installing the latest version', async () => {
|
test('succeed in installing the latest version', async () => {
|
||||||
const testVersion = 'latest';
|
const testVersion = 'latest';
|
||||||
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
||||||
|
process.env['INPUT_EXTENDED'] = 'false';
|
||||||
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
|
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
|
||||||
const result: main.ActionResult = await main.run();
|
const result: main.ActionResult = await main.run();
|
||||||
expect(result.exitcode).toBe(0);
|
expect(result.exitcode).toBe(0);
|
||||||
@ -62,8 +64,8 @@ describe('Integration testing run()', () => {
|
|||||||
|
|
||||||
test('fail to install the latest version due to 404 of brew', async () => {
|
test('fail to install the latest version due to 404 of brew', async () => {
|
||||||
process.env['INPUT_HUGO-VERSION'] = 'latest';
|
process.env['INPUT_HUGO-VERSION'] = 'latest';
|
||||||
|
process.env['INPUT_EXTENDED'] = 'false';
|
||||||
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(404);
|
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(404);
|
||||||
|
|
||||||
await expect(main.run()).rejects.toThrowError(FetchError);
|
await expect(main.run()).rejects.toThrowError(FetchError);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -6,7 +6,7 @@
|
|||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "actions-hugo",
|
"name": "actions-hugo",
|
||||||
"version": "2.6.0",
|
"version": "3.0.0",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -7,10 +7,10 @@ export default function getURL(
|
|||||||
const extendedStr = (extended: string): string => {
|
const extendedStr = (extended: string): string => {
|
||||||
if (extended === 'true') {
|
if (extended === 'true') {
|
||||||
return 'extended_';
|
return 'extended_';
|
||||||
} else {
|
} else if (extended === 'false') {
|
||||||
return '';
|
return '';
|
||||||
// } else {
|
} else {
|
||||||
// throw new Error(`Invalid input (extended): ${extended}`);
|
throw new Error(`Invalid input (extended): ${extended}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user