updated action template base from actions/typescript-action (#170)

This commit is contained in:
jdx 2023-10-16 19:18:57 -05:00 committed by GitHub
parent e8d5e65ea7
commit d661017ade
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 29023 additions and 10984 deletions

View file

@ -1,4 +1,4 @@
dist/
lib/ lib/
dist/
node_modules/ node_modules/
jest.config.js coverage/

View file

@ -2,10 +2,16 @@ version: 2
updates: updates:
- package-ecosystem: github-actions - package-ecosystem: github-actions
directory: / directory: /
labels:
- dependabot
- actions
schedule: schedule:
interval: weekly interval: weekly
- package-ecosystem: npm - package-ecosystem: npm
directory: / directory: /
labels:
- dependabot
- npm
schedule: schedule:
interval: weekly interval: weekly

83
.github/linters/.eslintrc.yml vendored Normal file
View file

@ -0,0 +1,83 @@
env:
node: true
es6: true
jest: true
globals:
Atomics: readonly
SharedArrayBuffer: readonly
ignorePatterns:
- '!.*'
- '**/node_modules/.*'
- '**/dist/.*'
- '**/coverage/.*'
- '*.json'
parser: '@typescript-eslint/parser'
parserOptions:
ecmaVersion: 2023
sourceType: module
project:
- './.github/linters/tsconfig.json'
- './tsconfig.json'
plugins:
- jest
- '@typescript-eslint'
extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
- plugin:github/recommended
- plugin:jest/recommended
rules:
{
'camelcase': 'off',
'eslint-comments/no-use': 'off',
'eslint-comments/no-unused-disable': 'off',
'i18n-text/no-en': 'off',
'import/no-namespace': 'off',
'no-console': 'off',
'no-unused-vars': 'off',
'prettier/prettier': 'error',
'semi': 'off',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/explicit-member-accessibility':
['error', { 'accessibility': 'no-public' }],
'@typescript-eslint/explicit-function-return-type':
['error', { 'allowExpressions': true }],
'@typescript-eslint/func-call-spacing': ['error', 'never'],
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-for-of': 'warn',
'@typescript-eslint/prefer-function-type': 'warn',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unbound-method': 'error'
}

7
.github/linters/.markdown-lint.yml vendored Normal file
View file

@ -0,0 +1,7 @@
# Unordered list style
MD004:
style: dash
# Ordered list item prefix
MD029:
style: one

10
.github/linters/.yaml-lint.yml vendored Normal file
View file

@ -0,0 +1,10 @@
rules:
document-end: disable
document-start:
level: warning
present: false
line-length:
level: warning
max: 80
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true

9
.github/linters/tsconfig.json vendored Normal file
View file

@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["../../__tests__/**/*", "../../src/**/*"],
"exclude": ["../../dist", "../../node_modules", "../../coverage", "*.json"]
}

View file

@ -1,8 +1,11 @@
# `dist/index.js` is a special file in Actions. # In TypeScript actions, `dist/index.js` is a special file. When you reference
# When you reference an action with `uses:` in a workflow, # an action with `uses:`, `dist/index.js` is the code that will be run. For this
# `index.js` is the code that will run. # project, the `dist/index.js` file is generated from other source files through
# For our project, we generate this file through a build process from other source files. # the build process. We need to make sure that the checked-in `dist/index.js`
# We need to make sure the checked-in `index.js` actually matches what we expect it to be. # file matches what is expected from the build.
#
# This workflow will fail if the checked-in `dist/index.js` file does not match
# what is expected from the build.
name: Check dist/ name: Check dist/
on: on:
@ -18,34 +21,43 @@ on:
jobs: jobs:
check-dist: check-dist:
name: Check dist/
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
statuses: write
steps: steps:
- uses: actions/checkout@v4 - name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Set Node.js 16.x - name: Setup Node.js
uses: actions/setup-node@v3.8.1 uses: actions/setup-node@v3
with: with:
node-version: 16.x node-version: 18
cache: npm
- name: Install dependencies - name: Install Dependencies
id: install
run: npm ci run: npm ci
- name: Rebuild the dist/ directory - name: Build dist/ Directory
run: | id: build
npm run build run: npm run bundle
npm run package
- name: Compare the expected and actual dist/ directories - name: Compare Expected and Actual Directories
id: diff
run: | run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:" echo "Detected uncommitted changes after build. See status below:"
git diff git diff --ignore-space-at-eol --text dist/
exit 1 exit 1
fi fi
id: diff
# If index.js was different than expected, upload the expected version as an artifact # If index.js was different than expected, upload the expected version as
# a workflow artifact.
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3
if: ${{ failure() && steps.diff.conclusion == 'failure' }} if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with: with:

41
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,41 @@
name: Continuous Integration
on:
pull_request:
push:
branches:
- main
- 'releases/*'
jobs:
test-typescript:
name: TypeScript Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- name: Install Dependencies
id: npm-ci
run: npm ci
- name: Check Format
id: npm-format-check
run: npm run format:check
- name: Lint
id: npm-lint
run: npm run lint
# - name: Test
# id: npm-ci-test
# run: npm run ci-test

View file

@ -1,22 +1,12 @@
# For most projects, this workflow file will not need changing; you simply need name: CodeQL
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on: on:
push: push:
branches: [ main ] branches:
- main
pull_request: pull_request:
# The branches below must be a subset of the branches above branches:
branches: [ main ] - main
schedule: schedule:
- cron: '31 7 * * 3' - cron: '31 7 * * 3'
@ -24,48 +14,35 @@ jobs:
analyze: analyze:
name: Analyze name: Analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
actions: read actions: read
checks: write
contents: read contents: read
security-events: write security-events: write
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
language: [ 'TypeScript' ] language:
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - TypeScript
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps: steps:
- name: Checkout repository - name: Checkout
id: checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
id: initialize
uses: github/codeql-action/init@v2 uses: github/codeql-action/init@v2
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
source-root: src source-root: src
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
id: autobuild
uses: github/codeql-action/autobuild@v2 uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
id: analyze
uses: github/codeql-action/analyze@v2 uses: github/codeql-action/analyze@v2

45
.github/workflows/linter.yml vendored Normal file
View file

@ -0,0 +1,45 @@
name: Lint Code Base
on:
pull_request:
branches:
- main
push:
branches-ignore:
- main
jobs:
lint:
name: Lint Code Base
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
statuses: write
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- name: Install Dependencies
id: install
run: npm ci
- name: Lint Code Base
id: super-linter
uses: super-linter/super-linter/slim@v5
env:
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TYPESCRIPT_DEFAULT_STYLE: prettier
VALIDATE_JSCPD: false
VALIDATE_NATURAL_LANGUAGE: false

View file

@ -25,9 +25,9 @@ jobs:
- macos-latest - macos-latest
tool_versions: tool_versions:
- | - |
nodejs 18 nodejs 20
- | - |
nodejs 16 nodejs 18
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4

6
.gitignore vendored
View file

@ -96,4 +96,8 @@ Thumbs.db
# Ignore built ts files # Ignore built ts files
__tests__/runner/* __tests__/runner/*
lib/**/*
# IDE files
.idea
.vscode
*.code-workspace

View file

@ -1,4 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# shellcheck disable=SC1091
. "$(dirname -- "$0")/_/husky.sh" . "$(dirname -- "$0")/_/husky.sh"
npm run all npm run all

View file

@ -1,3 +1,3 @@
dist/ dist/
lib/
node_modules/ node_modules/
coverage/

View file

@ -4,7 +4,13 @@
"useTabs": false, "useTabs": false,
"semi": false, "semi": false,
"singleQuote": true, "singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "none", "trailingComma": "none",
"bracketSpacing": false, "bracketSpacing": true,
"arrowParens": "avoid" "bracketSameLine": true,
"arrowParens": "avoid",
"proseWrap": "always",
"htmlWhitespaceSensitivity": "css",
"endOfLine": "lf"
} }

View file

@ -1,4 +1,4 @@
## Example Workflow # Example Workflow
```yaml ```yaml
name: test name: test

View file

@ -1,14 +0,0 @@
import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'
import {expect, test, jest} from '@jest/globals'
import {run} from '../src/main'
import {exec, getExecOutput} from '@actions/exec'
jest.mock('@actions/exec')
// shows how the runner will run a javascript action with env / stdout protocol
test.skip('install', async () => {
await run()
expect(exec).toBeCalledWith('rtx', ['install'])
})

View file

@ -10,13 +10,13 @@ inputs:
description: If present, this value will be written to the .tool-versions file description: If present, this value will be written to the .tool-versions file
install: install:
required: false required: false
default: true default: "true"
description: 'if false, will not run `rtx install`' description: 'if false, will not run `rtx install`'
outputs: outputs:
cache-hit: cache-hit:
description: 'A boolean value to indicate if a cache was hit.' description: 'A boolean value to indicate if a cache was hit.'
runs: runs:
using: node16 using: node20
main: dist/index.js main: dist/index.js
post: dist/cache-save/index.js post: dist/cache-save/index.js
post-if: success() post-if: success()

30510
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

51
dist/licenses.txt generated vendored
View file

@ -308,6 +308,28 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
@fastify/busboy
MIT
Copyright Brian White. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
@opentelemetry/api @opentelemetry/api
Apache-2.0 Apache-2.0
Apache License Apache License
@ -792,7 +814,7 @@ sax
ISC ISC
The ISC License The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors Copyright (c) 2010-2022 Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -811,7 +833,7 @@ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
`String.fromCodePoint` by Mathias Bynens used according to terms of MIT `String.fromCodePoint` by Mathias Bynens used according to terms of MIT
License, as follows: License, as follows:
Copyright Mathias Bynens <https://mathiasbynens.be/> Copyright (c) 2010-2022 Mathias Bynens <https://mathiasbynens.be/>
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
@ -895,6 +917,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
undici
MIT
MIT License
Copyright (c) Matteo Collina and Undici contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
uuid uuid
MIT MIT
The MIT License (MIT) The MIT License (MIT)

View file

@ -1,9 +0,0 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}

8686
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,9 @@
{ {
"name": "rtx-action", "name": "rtx-action",
"version": "1.1.1",
"private": true,
"description": "rtx tool setup action", "description": "rtx tool setup action",
"main": "lib/main.js", "version": "1.1.1",
"scripts": { "author": "jdx",
"build": "tsc", "private": true,
"format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'",
"lint": "eslint src/**/*.ts",
"package": "ncc build --source-map --license licenses.txt && ncc build -o dist/cache-save lib/cache-save.js --source-map",
"test": "jest",
"all": "npm run build && npm run format && npm run lint && npm run package && npm test",
"prepare": "husky install"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/jdx/rtx-action.git" "url": "git+https://github.com/jdx/rtx-action.git"
@ -23,29 +13,41 @@
"rtx", "rtx",
"setup" "setup"
], ],
"author": "", "exports": {
".": "./dist/index.js"
},
"scripts": {
"all": "npm run format:write && npm run lint && npm run package",
"bundle": "npm run format:write && npm run package",
"format:check": "prettier --check **/*.ts",
"format:write": "prettier --write **/*.ts",
"lint": "npx eslint . -c ./.github/linters/.eslintrc.yml",
"package": "ncc build src/index.ts --license licenses.txt",
"package:watch": "npm run package -- --watch",
"prepare": "husky install"
},
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^3.2.2", "@actions/cache": "^3.2.2",
"@actions/core": "^1.10.0", "@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/glob": "^0.4.0" "@actions/glob": "^0.4.0"
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node16": "^16.1.1",
"@types/node": "^20.8.6", "@types/node": "^20.8.6",
"@typescript-eslint/eslint-plugin": "^6.7.5", "@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.4", "@typescript-eslint/parser": "^6.7.5",
"@vercel/ncc": "^0.38.0", "@vercel/ncc": "^0.38.0",
"eslint": "^8.51.0", "eslint": "^8.51.0",
"eslint-plugin-github": "^4.10.1", "eslint-plugin-github": "^4.10.1",
"eslint-plugin-jest": "^27.4.2", "eslint-plugin-jest": "^27.4.2",
"eslint-plugin-jsonc": "^2.10.0",
"eslint-plugin-prettier": "^5.0.1", "eslint-plugin-prettier": "^5.0.1",
"husky": "^8.0.3", "husky": "^8.0.3",
"jest": "^29.7.0", "jest": "^29.7.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "^3.0.3", "prettier": "^3.0.3",
"ts-jest": "^29.1.1", "prettier-eslint": "^16.1.1",
"typescript": "^5.2.2" "typescript": "^5.2.2"
} }
} }

7
src/index.ts Normal file
View file

@ -0,0 +1,7 @@
/**
* The entrypoint for the action.
*/
import { run } from './main'
// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()

View file

@ -61,7 +61,7 @@ async function setupRTX(): Promise<void> {
} }
// returns true if tool_versions was set // returns true if tool_versions was set
async function setToolVersions(): Promise<Boolean> { async function setToolVersions(): Promise<boolean> {
const toolVersions = core.getInput('tool_versions', { required: false }) const toolVersions = core.getInput('tool_versions', { required: false })
if (toolVersions) { if (toolVersions) {
await fs.promises.writeFile('.tool-versions', toolVersions, { await fs.promises.writeFile('.tool-versions', toolVersions, {

View file

@ -1,8 +1,19 @@
{ {
"extends": "@tsconfig/node16/tsconfig.json", "$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": { "compilerOptions": {
"outDir": "./lib", /* Redirect output structure to the directory. */ "target": "ES2022",
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ "module": "NodeNext",
"rootDir": "./src",
"moduleResolution": "NodeNext",
"baseUrl": "./",
"sourceMap": true,
"outDir": "./dist",
"noImplicitAny": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"newLine": "lf"
}, },
"exclude": ["node_modules", "**/*.test.ts"] "exclude": ["./dist", "./node_modules", "./__tests__", "./coverage"]
} }