Skip to content

Commit

Permalink
Merge pull request #18 from d-koppenhagen/master
Browse files Browse the repository at this point in the history
refactor: switch to typescript implementation
  • Loading branch information
cmgriffing authored Dec 17, 2021
2 parents aeb0778 + a7348a7 commit 7b77d24
Show file tree
Hide file tree
Showing 563 changed files with 13,588 additions and 195,229 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
27 changes: 27 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"rules": {
"prettier/prettier": [
"error",
{
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"printWidth": 120,
"tabWidth": 2,
"semi": true
}
]
},
"env": {
"node": true,
"jest": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
}
}
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn run lint
- run: yarn run test
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Dependency directories
node_modules/

# Logs
logs
*.log
npm-debug.log*

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm build
git add .
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

*.js.map
*.d.ts
*.md
*.min.*
dist/**/*
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all"
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Enrique Gonzalez
Copyright (c) 2021 Chris Griffing

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v2
with:
node-version: "14"
node-version: "16"
- uses: cmgriffing/scully-gh-pages-action@v9
with:
access-token: ${{ secrets.ACCESS_TOKEN }}
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
```

> **NOTE:** In order to support `npm` and `yarn`, this Action relies on having a
> `build` script defined in your `package.json` file. Angular automatically creates one for you when you create a project via Angular-cli.
> `build` script defined in your `package.json` file. Angular automatically creates one for you when you create a project via Angular CLI.

### Knobs & Handles

Expand Down
95 changes: 95 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import * as github from '@actions/github';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as path from 'path';
import run from '../index';

const originalContext = { ...github.context };
const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE'];
const gitHubWorkspace = path.resolve('/checkout-tests/workspace');

type InputsMock = {
[name: string]: string;
};

let inputs: InputsMock = {};
let execSpy: jest.SpyInstance;

beforeAll(() => {
execSpy = jest.spyOn(exec, 'exec').mockImplementation(jest.fn());
jest.spyOn(io, 'cp').mockImplementation(jest.fn());

jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
return inputs[name];
});

jest.spyOn(github.context, 'repo', 'get').mockImplementation(() => {
return {
owner: 'foo',
repo: 'foo.github.io',
};
});

github.context.ref = 'refs/heads/some-ref';
github.context.sha = '1234567890123456789012345678901234567890';

process.env['GITHUB_WORKSPACE'] = gitHubWorkspace;
});

afterAll(() => {
delete process.env['GITHUB_WORKSPACE'];
if (originalGitHubWorkspace) {
process.env['GITHUB_WORKSPACE'] = originalGitHubWorkspace;
}

github.context.ref = originalContext.ref;
github.context.sha = originalContext.sha;

jest.restoreAllMocks();
});

beforeEach(() => {
jest.resetModules();
inputs = {
'access-token': 'SECRET',
};
});

describe('scully Publish action', () => {
it('returns an error when no access token is given', async () => {
inputs['access-token'] = '';
const setFailedSpy = jest.spyOn(core, 'setFailed');

await run();

expect(setFailedSpy).toBeCalledWith(
'No personal access token found. Please provide one by setting the `access-token` input for this action.',
);
});

it('skips if deploy branch is the same as the current git head', async () => {
inputs['deploy-branch'] = 'some-ref';
github.context.ref = 'refs/heads/some-ref';

await expect(run()).resolves.not.toThrowError();
});

it('calls angular build without args', async () => {
inputs['build-args'] = '';
inputs['scully-args'] = '';

await run();

expect(execSpy).toHaveBeenLastCalledWith('yarn run build ', []);
});

it('calls angular build with args', async () => {
inputs['build-args'] = '--prefix-paths --no-uglify';
inputs['scully-args'] = '';

await run();

expect(execSpy).toHaveBeenLastCalledWith('yarn run build -- --prefix-paths --no-uglify', []);
});
});
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ inputs:
required: false
default: ""
runs:
using: "node12"
main: "index.js"
using: "node16"
main: "./dist/index.js"
1 change: 1 addition & 0 deletions dist/index.js

Large diffs are not rendered by default.

120 changes: 0 additions & 120 deletions index.js

This file was deleted.

Loading

0 comments on commit 7b77d24

Please sign in to comment.