Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: downloads for mac and win #643

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ on:

jobs:
CodeQL-Build:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: javascript

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
4 changes: 2 additions & 2 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:

jobs:
dependency-review:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/dependency-review-action@v3
- uses: actions/dependency-review-action@v4
2 changes: 1 addition & 1 deletion .github/workflows/dev-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:

jobs:
dev-image-test:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/label-commenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

jobs:
comment:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/purge-readme-image-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
purge:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:

- run: >
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
release:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ jobs:
- 'windows-latest'
hugo-version:
- 'latest'
- '0.61.0'
- '0.103.0'
extended:
- true
- false
steps:
- uses: actions/checkout@v4

- name: Setup Hugo
uses: peaceiris/actions-hugo@v2.6.0
uses: peaceiris/actions-hugo@v2
with:
hugo-version: ${{ matrix.hugo-version }}
extended: ${{ matrix.extended }}

- name: Run hugo version
run: echo "::set-output name=hugo_version::$(hugo version)"
run: echo "hugo_version=$(hugo version)" >> $GITHUB_OUTPUT
id: hugo_version

- name: '${{ steps.hugo_version.outputs.hugo_version }}'
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
fail-fast: false
matrix:
os:
- 'ubuntu-22.04'
- 'ubuntu-20.04'
- 'ubuntu-latest'
- 'macos-latest'
Expand All @@ -33,23 +32,23 @@ jobs:
- run: npm ci

- name: Run prettier
if: startsWith(matrix.os, 'ubuntu-22.04')
if: startsWith(matrix.os, 'ubuntu-latest')
run: npm run format:check

- name: Run eslint
if: startsWith(matrix.os, 'ubuntu-22.04')
if: startsWith(matrix.os, 'ubuntu-latest')
run: npm run lint

- name: Run ncc
if: startsWith(matrix.os, 'ubuntu-22.04')
if: startsWith(matrix.os, 'ubuntu-latest')
run: npm run build

- run: npm test

- name: Upload test coverage as artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.os }}
path: coverage

- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
2 changes: 1 addition & 1 deletion .github/workflows/update-major-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
update:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

Expand Down
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ We no longer build or pull a Hugo docker image.
Thanks to this change, we can complete this action in less than a few seconds.
(A docker base action was taking about 1 min or more execution time to build and pull a docker image.)

| OS (runs-on) | ubuntu-latest, ubuntu-20.04, ubuntu-22.04 | macos-latest | windows-2019 |
| OS (runs-on) | ubuntu-latest, ubuntu-20.04 | macos-latest | windows-latest |
|---|:---:|:---:|:---:|
| Support | ✅️ | ✅️ | ✅️ |

Expand Down Expand Up @@ -81,7 +81,7 @@ on:

jobs:
deploy:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
Expand Down Expand Up @@ -151,13 +151,27 @@ This action fetches the latest version of Hugo by [hugo | Homebrew Formulae](htt
### ⭐️ Caching Hugo Modules

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
- uses: actions/cache@v4
with:
path: /home/runner/.cache/hugo_cache # <-- with hugo version v0.116.0 and above
# path: /tmp/hugo_cache # <-- with hugo version < v0.116.0
path: ${{ env.HUGO_CACHEDIR }} # <- Use the same env variable just right here
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-hugomod-
Expand Down Expand Up @@ -247,7 +261,7 @@ on:

jobs:
deploy:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
Expand Down Expand Up @@ -300,7 +314,7 @@ on:

jobs:
deploy:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
Expand Down Expand Up @@ -352,7 +366,7 @@ on:

jobs:
deploy:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
Expand Down
6 changes: 3 additions & 3 deletions __tests__/get-arch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import getArch from '../src/get-arch';

describe('getArch', () => {
test('processor architecture', () => {
expect(getArch('x64')).toBe('64bit');
expect(getArch('arm')).toBe('ARM');
expect(getArch('arm64')).toBe('ARM64');
expect(getArch('x64')).toBe('amd64');
expect(getArch('arm')).toBe('arm');
expect(getArch('arm64')).toBe('arm64');
});

test('exception', () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/get-os.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import getOS from '../src/get-os';

describe('getOS', () => {
test('os type', () => {
expect(getOS('linux')).toBe('Linux');
expect(getOS('darwin')).toBe('macOS');
expect(getOS('win32')).toBe('Windows');
expect(getOS('linux')).toBe('linux');
expect(getOS('darwin')).toBe('darwin');
expect(getOS('win32')).toBe('windows');
});

test('exception', () => {
Expand Down
28 changes: 14 additions & 14 deletions __tests__/get-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import getURL from '../src/get-url';

describe('getURL()', () => {
test('get a URL to an asset for each platform', () => {
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.58.2';
const urlLinux = `${baseURL}/hugo_0.58.2_Linux-64bit.tar.gz`;
const urlLinuxExtended = `${baseURL}/hugo_extended_0.58.2_Linux-64bit.tar.gz`;
const urlMacOS = `${baseURL}/hugo_0.58.2_macOS-64bit.tar.gz`;
const urlMacOSExtended = `${baseURL}/hugo_extended_0.58.2_macOS-64bit.tar.gz`;
const urlWindows = `${baseURL}/hugo_0.58.2_Windows-64bit.zip`;
expect(getURL('Linux', '64bit', 'false', '0.58.2')).toBe(urlLinux);
expect(getURL('Linux', '64bit', 'true', '0.58.2')).not.toBe(urlLinux);
expect(getURL('MyOS', '64bit', 'false', '0.58.2')).not.toBe(urlLinux);
expect(getURL('Linux', '64bit', 'false', '0.58.1')).not.toBe(urlLinux);
expect(getURL('Linux', '64bit', 'true', '0.58.2')).toBe(urlLinuxExtended);
expect(getURL('macOS', '64bit', 'false', '0.58.2')).toBe(urlMacOS);
expect(getURL('macOS', '64bit', 'true', '0.58.2')).toBe(urlMacOSExtended);
expect(getURL('Windows', '64bit', 'false', '0.58.2')).toBe(urlWindows);
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.122.0';
const urlLinux = `${baseURL}/hugo_0.122.0_linux-amd64.tar.gz`;
const urlLinuxExtended = `${baseURL}/hugo_extended_0.122.0_linux-amd64.tar.gz`;
const urlMacOS = `${baseURL}/hugo_0.122.0_darwin-universal.tar.gz`;
const urlMacOSExtended = `${baseURL}/hugo_extended_0.122.0_darwin-universal.tar.gz`;
const urlWindows = `${baseURL}/hugo_0.122.0_windows-amd64.zip`;
expect(getURL('linux', 'amd64', 'false', '0.122.0')).toBe(urlLinux);
expect(getURL('linux', 'amd64', 'true', '0.122.0')).not.toBe(urlLinux);
expect(getURL('MyOS', 'amd64', 'false', '0.122.0')).not.toBe(urlLinux);
expect(getURL('linux', 'amd64', 'false', '0.121.0')).not.toBe(urlLinux);
expect(getURL('linux', 'amd64', 'true', '0.122.0')).toBe(urlLinuxExtended);
expect(getURL('darwin', 'universal', 'false', '0.122.0')).toBe(urlMacOS);
expect(getURL('darwin', 'universal', 'true', '0.122.0')).toBe(urlMacOSExtended);
expect(getURL('windows', 'amd64', 'false', '0.122.0')).toBe(urlWindows);
});
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/get-arch.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export default function getArch(arch: string): string {
switch (arch) {
case 'x64':
return '64bit';
return 'amd64';
case 'arm':
return 'ARM';
return 'arm';
case 'arm64':
return 'ARM64';
return 'arm64';
case 'universal':
return 'universal';
default:
throw new Error(`${arch} is not supported`);
}
Expand Down
6 changes: 3 additions & 3 deletions src/get-os.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export default function getOS(platform: string): string {
switch (platform) {
case 'linux':
return 'Linux';
return 'linux';
case 'darwin':
return 'macOS';
return 'darwin';
case 'win32':
return 'Windows';
return 'windows';
default:
throw new Error(`${platform} is not supported`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/get-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function getURL(
};

const ext = (os: string): string => {
if (os === 'Windows') {
if (os === 'windows') {
return 'zip';
} else {
return 'tar.gz';
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as main from './main';
try {
await main.run();
} catch (e) {
// eslint-ignore-next-line
core.setFailed(`Action failed with error ${e.message}`);
}
})();