Skip to content

Commit

Permalink
Feat: Support macOS and Windows, migrate JavaScript to TypeScript (#32)
Browse files Browse the repository at this point in the history
- Support macOS and Windows (Close #24 )
- Refactoring
  - Error handling
  - TypeScript
- Prettier (Close #29 )
- GHA: Add upload-artifact step for test coverage
- deps: Install husky
  • Loading branch information
peaceiris committed Sep 21, 2019
1 parent 4d54b90 commit dc85417
Show file tree
Hide file tree
Showing 24 changed files with 924 additions and 168 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
34 changes: 18 additions & 16 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2019
},
"rules": {
}
}
22 changes: 18 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,46 @@ jobs:

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Install dependencies
run: npm ci

- name: Format check
run: npm run format:check

- name: Lint
run: npm run lint

# - name: Test script
# run: npm test
- name: Test
run: npm test

- uses: actions/upload-artifact@master
with:
name: coverage
path: coverage

# - name: Build production
# run: npm run build


test-prod:
runs-on: ubuntu-18.04
runs-on: ${{ matrix.os }}
needs: test
strategy:
matrix:
# os: ['ubuntu-18.04', 'macOS-10.14']
os: ['ubuntu-18.04', 'macOS-10.14', 'windows-2019']
# hugo-version: ['latest']
# extended: [true]
hugo-version: ['latest', '0.58.2']
hugo-version: ['latest', '0.57.2']
extended: [true, false]

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Test action
uses: ./
Expand Down
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@

We can run Hugo on a virtual machine of GitHub Actions by this Hugo action. Hugo extended version and Hugo Modules are supported.

From `v2.0.0`, this Hugo action migrated to a JavaScript action. We no longer build or pull a Hugo docker image. Thanks to this change, we can complete this action less than **2 sec**. (A docker base action was taking about 1 min or more execution time to build or pull.)
From `v2.0.0`, this Hugo action migrated to a JavaScript (TypeScript) action. We no longer build or pull a Hugo docker image. Thanks to this change, we can complete this action less than **3 sec**. (A docker base action was taking about 1 min or more execution time to build or pull.)

| OS (runs-on) | ubuntu-18.04 | macOS-10.14 | windows-2019 |
|---|:---:|:---:|:---:|
| Support | ✅️ | ✅️ | ✅️ |

| Hugo type | Hugo Extended | Hugo Modules | Latest Hugo |
|---|:---:|:---:|:---:|
| Support | ✅️ | ✅️ | ✅️ |



Expand Down Expand Up @@ -41,13 +49,15 @@ on:
jobs:
build-deploy:
runs-on: ubuntu-18.04
# runs-on: macOS-10.14
# runs-on: windows-2019
steps:
- uses: actions/checkout@master

- name: Setup Hugo
uses: peaceiris/actions-hugo@v2.1.0
with:
hugo-version: '0.58.2'
hugo-version: '0.58.3'

- name: Build
run: hugo --gc --minify --cleanDestinationDir
Expand All @@ -70,7 +80,7 @@ jobs:
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2.1.0
with:
hugo-version: '0.58.2'
hugo-version: '0.58.3'
extended: true
```
Expand Down
18 changes: 18 additions & 0 deletions __tests__/get-os.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import getOS from '../src/get-os';

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

test('test exception', () => {
// expect(() => {
// getOS("win32");
// }).toThrowError("Windows is not supported");
expect(() => {
getOS('centos');
}).toThrowError('centos is not supported');
});
});
22 changes: 22 additions & 0 deletions __tests__/get-url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import getURL from '../src/get-url';

describe('getURL()', () => {
test('test', () => {
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 urlWindows = `${baseURL}/hugo_0.58.2_Windows-64bit.zip`;
expect(getURL('Linux', 'false', '0.58.2')).toBe(urlLinux);
expect(getURL('Linux', 'true', '0.58.2')).toBe(urlLinuxExtended);
expect(getURL('macOS', 'false', '0.58.2')).toBe(urlMacOS);
expect(getURL('Windows', 'false', '0.58.2')).toBe(urlWindows);
});

// test("test exception", () => {
// expect(() => {
// getURL("Linux", "hoge", "0.58.2");
// }).toThrowError("Invalid input (extended): hoge");
// });
});
23 changes: 0 additions & 23 deletions __tests__/index.test.js

This file was deleted.

11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}
39 changes: 20 additions & 19 deletions lib/get-latest-version.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
function getLatestVersion() {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
const url = "https://formulae.brew.sh/api/formula/hugo.json";
xhr.open("GET", url);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
const result = JSON.parse(xhr.responseText);
const latestVersion = result.versions.stable;
resolve(latestVersion);
} else if (xhr.readyState === 4 && xhr.status !== 200) {
reject(`ERROR: got status ${xhr.status} of ${url}`);
}
};
});
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
const url = 'https://formulae.brew.sh/api/formula/hugo.json';
xhr.open('GET', url);
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
const result = JSON.parse(xhr.responseText);
const latestVersion = result.versions.stable;
resolve(latestVersion);
}
else if (xhr.readyState === 4 && xhr.status !== 200) {
reject(`ERROR: got status ${xhr.status} of ${url}`);
}
};
});
}

module.exports = getLatestVersion;
exports.default = getLatestVersion;
18 changes: 18 additions & 0 deletions lib/get-os.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getOS(platform) {
if (platform === 'linux') {
return 'Linux';
}
else if (platform === 'darwin') {
return 'macOS';
}
else if (platform === 'win32') {
return 'Windows';
// throw new Error("Windows is not supported");
}
else {
throw new Error(`${platform} is not supported`);
}
}
exports.default = getOS;
27 changes: 27 additions & 0 deletions lib/get-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getURL(os, extended, version) {
const extendedStr = (extended) => {
if (extended === 'true') {
return 'extended_';
}
else {
return '';
// } else {
// throw new Error(`Invalid input (extended): ${extended}`);
}
};
const ext = (os) => {
if (os === 'Windows') {
return 'zip';
}
else {
return 'tar.gz';
}
};
const hugoName = `hugo_${extendedStr(extended)}${version}_${os}-64bit`;
const baseURL = 'https://github.com/gohugoio/hugo/releases/download';
const url = `${baseURL}/v${version}/${hugoName}.${ext(os)}`;
return url;
}
exports.default = getURL;
Loading

0 comments on commit dc85417

Please sign in to comment.