Skip to content

Commit 143fac7

Browse files
authored
V2 (#22)
* feat: combine package updates and switch to using pnpm * feat: switch to pnpm * ci: upgrade action version * feat: support api token * feat: match config of action-cloudflare-cache * test: fix tests * test: format all ts files * chore: build latest
1 parent bc8434a commit 143fac7

17 files changed

+38965
-8116
lines changed

.eslintrc.json

+55-54
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
1-
{
2-
"plugins": ["jest", "@typescript-eslint"],
3-
"extends": ["plugin:github/recommended"],
4-
"parser": "@typescript-eslint/parser",
5-
"parserOptions": {
6-
"ecmaVersion": 9,
7-
"sourceType": "module",
8-
"project": "./tsconfig.json"
9-
},
10-
"rules": {
11-
"eslint-comments/no-use": "off",
12-
"import/no-namespace": "off",
13-
"no-unused-vars": "off",
14-
"@typescript-eslint/no-unused-vars": "error",
15-
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
16-
"@typescript-eslint/no-require-imports": "error",
17-
"@typescript-eslint/array-type": "error",
18-
"@typescript-eslint/await-thenable": "error",
19-
"@typescript-eslint/ban-ts-comment": "error",
20-
"camelcase": "off",
21-
"@typescript-eslint/consistent-type-assertions": "error",
22-
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
23-
"@typescript-eslint/func-call-spacing": ["error", "never"],
24-
"@typescript-eslint/no-array-constructor": "error",
25-
"@typescript-eslint/no-empty-interface": "error",
26-
"@typescript-eslint/no-explicit-any": "error",
27-
"@typescript-eslint/no-extraneous-class": "error",
28-
"@typescript-eslint/no-for-in-array": "error",
29-
"@typescript-eslint/no-inferrable-types": "error",
30-
"@typescript-eslint/no-misused-new": "error",
31-
"@typescript-eslint/no-namespace": "error",
32-
"@typescript-eslint/no-non-null-assertion": "warn",
33-
"@typescript-eslint/no-unnecessary-qualifier": "error",
34-
"@typescript-eslint/no-unnecessary-type-assertion": "error",
35-
"@typescript-eslint/no-useless-constructor": "error",
36-
"@typescript-eslint/no-var-requires": "error",
37-
"@typescript-eslint/prefer-for-of": "warn",
38-
"@typescript-eslint/prefer-function-type": "warn",
39-
"@typescript-eslint/prefer-includes": "error",
40-
"@typescript-eslint/prefer-string-starts-ends-with": "error",
41-
"@typescript-eslint/promise-function-async": "error",
42-
"@typescript-eslint/require-array-sort-compare": "error",
43-
"@typescript-eslint/restrict-plus-operands": "error",
44-
"semi": "off",
45-
"@typescript-eslint/semi": ["error", "never"],
46-
"@typescript-eslint/type-annotation-spacing": "error",
47-
"@typescript-eslint/unbound-method": "error"
48-
},
49-
"env": {
50-
"node": true,
51-
"es6": true,
52-
"jest/globals": true
53-
}
54-
}
1+
{
2+
"plugins": ["jest", "@typescript-eslint"],
3+
"extends": ["plugin:github/recommended"],
4+
"parser": "@typescript-eslint/parser",
5+
"parserOptions": {
6+
"ecmaVersion": 9,
7+
"sourceType": "module",
8+
"project": "./tsconfig.json"
9+
},
10+
"rules": {
11+
"eslint-comments/no-use": "off",
12+
"import/no-namespace": "off",
13+
"no-unused-vars": "off",
14+
"@typescript-eslint/no-unused-vars": "error",
15+
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
16+
"@typescript-eslint/no-require-imports": "error",
17+
"@typescript-eslint/array-type": "error",
18+
"@typescript-eslint/await-thenable": "error",
19+
"@typescript-eslint/ban-ts-comment": "error",
20+
"camelcase": "off",
21+
"@typescript-eslint/consistent-type-assertions": "error",
22+
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
23+
"@typescript-eslint/func-call-spacing": ["error", "never"],
24+
"@typescript-eslint/no-array-constructor": "error",
25+
"@typescript-eslint/no-empty-interface": "error",
26+
"@typescript-eslint/no-explicit-any": "error",
27+
"@typescript-eslint/no-extraneous-class": "error",
28+
"@typescript-eslint/no-for-in-array": "error",
29+
"@typescript-eslint/no-inferrable-types": "error",
30+
"@typescript-eslint/no-misused-new": "error",
31+
"@typescript-eslint/no-namespace": "error",
32+
"@typescript-eslint/no-non-null-assertion": "warn",
33+
"@typescript-eslint/no-unnecessary-qualifier": "error",
34+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
35+
"@typescript-eslint/no-useless-constructor": "error",
36+
"@typescript-eslint/no-var-requires": "error",
37+
"@typescript-eslint/prefer-for-of": "warn",
38+
"@typescript-eslint/prefer-function-type": "warn",
39+
"@typescript-eslint/prefer-includes": "error",
40+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
41+
"@typescript-eslint/promise-function-async": "error",
42+
"@typescript-eslint/require-array-sort-compare": "error",
43+
"@typescript-eslint/restrict-plus-operands": "error",
44+
"semi": "off",
45+
"@typescript-eslint/semi": ["error", "never"],
46+
"@typescript-eslint/type-annotation-spacing": "error",
47+
"@typescript-eslint/unbound-method": "error",
48+
"i18n-text/no-en": "off"
49+
},
50+
"env": {
51+
"node": true,
52+
"es6": true,
53+
"jest/globals": true
54+
}
55+
}

.github/workflows/action_check.yml

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
name: 'Action Test'
2-
on:
3-
pull_request:
4-
branches:
5-
- main
6-
push:
7-
branches:
8-
- '**'
9-
tags-ignore:
10-
- '**'
11-
paths:
12-
- "**.ts"
13-
- ".github/workflows/action_check.yml"
14-
- "action.yml"
15-
- "dist/index.js"
16-
17-
jobs:
18-
test:
19-
runs-on: ubuntu-latest
20-
steps:
21-
- name: Checkout
22-
uses: actions/checkout@v2
23-
24-
- name: Test Action
25-
uses: ./
26-
with:
27-
account: ${{ secrets.TEST_ACCOUNT }}
28-
project: ${{ secrets.TEST_PROJECT }}
29-
email: ${{ secrets.TEST_EMAIL }}
30-
global_token: ${{ secrets.TEST_TOKEN }}
31-
1+
name: 'Action Test'
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
push:
7+
branches:
8+
- '**'
9+
tags-ignore:
10+
- '**'
11+
paths:
12+
- "**.ts"
13+
- ".github/workflows/action_check.yml"
14+
- "action.yml"
15+
- "dist/index.js"
16+
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Test Action
25+
uses: ./
26+
with:
27+
account: ${{ secrets.TEST_ACCOUNT }}
28+
project: ${{ secrets.TEST_PROJECT }}
29+
email: ${{ secrets.TEST_EMAIL }}
30+
global_token: ${{ secrets.TEST_TOKEN }}
31+

.github/workflows/code-ql.yml

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
name: "CodeQL"
2-
3-
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
8-
schedule:
9-
- cron: '28 19 * * 6'
10-
11-
jobs:
12-
analyze:
13-
name: Analyze
14-
runs-on: ubuntu-latest
15-
permissions:
16-
actions: read
17-
contents: read
18-
security-events: write
19-
20-
steps:
21-
- name: Checkout repository
22-
uses: actions/checkout@v2
23-
24-
- name: Initialize CodeQL
25-
uses: github/codeql-action/init@v1
26-
with:
27-
languages: javascript
28-
29-
30-
- name: Perform CodeQL Analysis
31-
uses: github/codeql-action/analyze@v1
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '28 19 * * 6'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Initialize CodeQL
25+
uses: github/codeql-action/init@v3
26+
with:
27+
languages: typescript
28+
29+
30+
- name: Perform CodeQL Analysis
31+
uses: github/codeql-action/analyze@v3

.github/workflows/typescript.yml

+37-15
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,56 @@ on:
1111
paths:
1212
- "**.ts"
1313
- ".github/workflows/typescript.yml"
14+
- "package.json"
1415

1516
jobs:
1617
test:
1718
runs-on: ubuntu-latest
1819
steps:
19-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2021

21-
- name: Get yarn cache directory path
22-
id: yarn-cache-dir-path
23-
run: echo "::set-output name=dir::$(yarn cache dir)"
22+
- uses: pnpm/action-setup@v4
23+
with:
24+
version: 9
25+
26+
- name: Install Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: 'pnpm'
2431

25-
- name: Download Cache
26-
uses: actions/cache@v2
27-
id: yarn-cache
32+
- name: Get pnpm store directory
33+
shell: bash
34+
run: |
35+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
36+
37+
- uses: actions/cache@v4
38+
name: Setup pnpm cache
2839
with:
29-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
30-
key: yarn-${{ hashFiles('**/yarn.lock') }}
40+
path: ${{ env.STORE_PATH }}
41+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
3142
restore-keys: |
32-
yarn-
43+
${{ runner.os }}-pnpm-store-
3344
34-
- name: Install Packages
35-
run: yarn install
45+
- name: Install dependencies
46+
run: pnpm install
3647

3748
- name: Lint
38-
run: yarn run lint
49+
run: pnpm lint
3950

4051
- name: Check format
41-
run: yarn run format-check
52+
run: pnpm format:check
4253

4354
- name: Run tests
44-
run: yarn run test
55+
run: npm run test
56+
57+
- name: Rebuild the dist/ directory
58+
run: npm run build
59+
60+
- name: Compare the expected and actual dist/ directories
61+
run: |
62+
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
63+
echo "Detected uncommitted changes after build. See status below:"
64+
git diff
65+
exit 1
66+
fi

.prettierrc.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
{
2-
"printWidth": 80,
3-
"tabWidth": 2,
4-
"useTabs": false,
5-
"semi": false,
6-
"singleQuote": true,
7-
"trailingComma": "none",
8-
"bracketSpacing": false,
9-
"arrowParens": "avoid"
10-
}
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "none",
8+
"bracketSpacing": false,
9+
"arrowParens": "avoid"
10+
}

__tests__/cloudflare.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ test('Failed Token Check', async () => {
99
let conf = config.create_config()
1010

1111
expect(cloudflare.check_auth(conf)).rejects.toThrow(
12-
'Error when checking token. Request failed with status code 400'
12+
'Error when checking token. AxiosError: Request failed with status code 400'
1313
)
1414
})

__tests__/config.test.ts

+26-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
import * as config from '../src/config'
22

3-
test('No Auth', async () => {
4-
expect(() => config.create_config()).toThrow(
5-
'Need to have global_token with email set'
6-
)
7-
})
3+
describe('Config', () => {
4+
test('No Auth', async () => {
5+
expect(() => config.create_config()).toThrow(
6+
'Need to have either an api_token or global_token with email set'
7+
)
8+
})
89

9-
test('Half Legacy Auth', async () => {
10-
process.env['INPUT_GLOBAL_TOKEN'] = '4'
11-
expect(() => config.create_config()).toThrow(
12-
'Need email set when using global token'
13-
)
14-
})
10+
test('Half Legacy Auth', async () => {
11+
process.env['INPUT_GLOBAL_TOKEN'] = '4'
12+
expect(() => config.create_config()).toThrow(
13+
'Need email set when using global token'
14+
)
15+
})
1516

16-
test('Legacy Auth', async () => {
17-
process.env['INPUT_ACCOUNT'] = '1'
18-
process.env['INPUT_PROJECT'] = 'test'
19-
process.env['INPUT_GLOBAL_TOKEN'] = '2'
20-
process.env['INPUT_EMAIL'] = '[email protected]'
21-
let conf = config.create_config()
22-
expect(conf.token_method).toEqual('legacy')
23-
expect(conf.instance.defaults.headers['X-Auth-Key']).toEqual('2')
24-
expect(conf.instance.defaults.headers['X-Auth-Email']).toEqual(
25-
26-
)
27-
expect(conf.project_name).toEqual('test')
28-
expect(conf.account_id).toEqual('1')
17+
test('Legacy Auth', async () => {
18+
process.env['INPUT_ACCOUNT'] = '1'
19+
process.env['INPUT_PROJECT'] = 'test'
20+
process.env['INPUT_GLOBAL_TOKEN'] = '2'
21+
process.env['INPUT_EMAIL'] = '[email protected]'
22+
let conf = config.create_config()
23+
expect(conf.token_method).toEqual('legacy')
24+
expect(conf.instance.defaults.headers['X-Auth-Key']).toEqual('2')
25+
expect(conf.instance.defaults.headers['X-Auth-Email']).toEqual(
26+
27+
)
28+
expect(conf.project_name).toEqual('test')
29+
expect(conf.account_id).toEqual('1')
30+
})
2931
})

0 commit comments

Comments
 (0)