测试初始化
This commit is contained in:
commit
0507fb9ced
61
.env.example
Normal file
61
.env.example
Normal file
@ -0,0 +1,61 @@
|
||||
# dotenv-linter:off IncorrectDelimiter
|
||||
|
||||
# Do not commit your actual .env file to Git! This may contain secrets or other
|
||||
# private information.
|
||||
|
||||
# Enable/disable step debug logging (default: `false`). For local debugging, it
|
||||
# may be useful to set it to `true`.
|
||||
ACTIONS_STEP_DEBUG=true
|
||||
|
||||
# GitHub Actions inputs should follow `INPUT_<name>` format (case-sensitive).
|
||||
# Hyphens should not be converted to underscores!
|
||||
INPUT_MILLISECONDS=2400
|
||||
|
||||
# GitHub Actions default environment variables. These are set for every run of a
|
||||
# workflow and can be used in your actions. Setting the value here will override
|
||||
# any value set by the local-action tool.
|
||||
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
|
||||
|
||||
# CI="true"
|
||||
# GITHUB_ACTION=""
|
||||
# GITHUB_ACTION_PATH=""
|
||||
# GITHUB_ACTION_REPOSITORY=""
|
||||
# GITHUB_ACTIONS=""
|
||||
# GITHUB_ACTOR=""
|
||||
# GITHUB_ACTOR_ID=""
|
||||
# GITHUB_API_URL=""
|
||||
# GITHUB_BASE_REF=""
|
||||
# GITHUB_ENV=""
|
||||
# GITHUB_EVENT_NAME=""
|
||||
# GITHUB_EVENT_PATH=""
|
||||
# GITHUB_GRAPHQL_URL=""
|
||||
# GITHUB_HEAD_REF=""
|
||||
# GITHUB_JOB=""
|
||||
# GITHUB_OUTPUT=""
|
||||
# GITHUB_PATH=""
|
||||
# GITHUB_REF=""
|
||||
# GITHUB_REF_NAME=""
|
||||
# GITHUB_REF_PROTECTED=""
|
||||
# GITHUB_REF_TYPE=""
|
||||
# GITHUB_REPOSITORY=""
|
||||
# GITHUB_REPOSITORY_ID=""
|
||||
# GITHUB_REPOSITORY_OWNER=""
|
||||
# GITHUB_REPOSITORY_OWNER_ID=""
|
||||
# GITHUB_RETENTION_DAYS=""
|
||||
# GITHUB_RUN_ATTEMPT=""
|
||||
# GITHUB_RUN_ID=""
|
||||
# GITHUB_RUN_NUMBER=""
|
||||
# GITHUB_SERVER_URL=""
|
||||
# GITHUB_SHA=""
|
||||
# GITHUB_STEP_SUMMARY=""
|
||||
# GITHUB_TRIGGERING_ACTOR=""
|
||||
# GITHUB_WORKFLOW=""
|
||||
# GITHUB_WORKFLOW_REF=""
|
||||
# GITHUB_WORKFLOW_SHA=""
|
||||
# GITHUB_WORKSPACE=""
|
||||
# RUNNER_ARCH=""
|
||||
# RUNNER_DEBUG=""
|
||||
# RUNNER_NAME=""
|
||||
# RUNNER_OS=""
|
||||
# RUNNER_TEMP=""
|
||||
# RUNNER_TOOL_CACHE=""
|
||||
3
.gitattributes
vendored
Normal file
3
.gitattributes
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
* text=auto eol=lf
|
||||
|
||||
dist/** -diff linguist-generated=true
|
||||
102
.gitignore
vendored
Normal file
102
.gitignore
vendored
Normal file
@ -0,0 +1,102 @@
|
||||
# Dependency directory
|
||||
node_modules
|
||||
|
||||
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# OS metadata
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Ignore built ts files
|
||||
__tests__/runner/*
|
||||
|
||||
# IDE files
|
||||
.idea
|
||||
*.code-workspace
|
||||
18
.licensed.yml
Normal file
18
.licensed.yml
Normal file
@ -0,0 +1,18 @@
|
||||
# See: https://github.com/licensee/licensed/blob/main/docs/configuration.md
|
||||
|
||||
sources:
|
||||
npm: true
|
||||
|
||||
allowed:
|
||||
- apache-2.0
|
||||
- bsd-2-clause
|
||||
- bsd-3-clause
|
||||
- isc
|
||||
- mit
|
||||
- cc0-1.0
|
||||
- other
|
||||
|
||||
ignored:
|
||||
npm:
|
||||
# Used by Rollup.js when building in GitHub Actions
|
||||
- '@rollup/rollup-linux-x64-gnu'
|
||||
24
.markdown-lint.yml
Normal file
24
.markdown-lint.yml
Normal file
@ -0,0 +1,24 @@
|
||||
# See: https://github.com/DavidAnson/markdownlint
|
||||
|
||||
# Unordered list style
|
||||
MD004:
|
||||
style: dash
|
||||
|
||||
# Disable line length for tables
|
||||
MD013:
|
||||
tables: false
|
||||
|
||||
# Ordered list item prefix
|
||||
MD029:
|
||||
style: one
|
||||
|
||||
# Spaces after list markers
|
||||
MD030:
|
||||
ul_single: 1
|
||||
ol_single: 1
|
||||
ul_multi: 1
|
||||
ol_multi: 1
|
||||
|
||||
# Code block style
|
||||
MD046:
|
||||
style: fenced
|
||||
1
.node-version
Normal file
1
.node-version
Normal file
@ -0,0 +1 @@
|
||||
20.18.1
|
||||
5
.prettierignore
Normal file
5
.prettierignore
Normal file
@ -0,0 +1,5 @@
|
||||
.DS_Store
|
||||
.licenses/
|
||||
dist/
|
||||
node_modules/
|
||||
coverage/
|
||||
16
.prettierrc.yml
Normal file
16
.prettierrc.yml
Normal file
@ -0,0 +1,16 @@
|
||||
# See: https://prettier.io/docs/en/configuration
|
||||
|
||||
printWidth: 80
|
||||
tabWidth: 2
|
||||
useTabs: false
|
||||
semi: false
|
||||
singleQuote: true
|
||||
quoteProps: as-needed
|
||||
jsxSingleQuote: false
|
||||
trailingComma: none
|
||||
bracketSpacing: true
|
||||
bracketSameLine: true
|
||||
arrowParens: always
|
||||
proseWrap: always
|
||||
htmlWhitespaceSensitivity: css
|
||||
endOfLine: lf
|
||||
14
.yaml-lint.yml
Normal file
14
.yaml-lint.yml
Normal file
@ -0,0 +1,14 @@
|
||||
# See: https://yamllint.readthedocs.io/en/stable/
|
||||
|
||||
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
|
||||
ignore:
|
||||
- .licenses/
|
||||
306
README.md
Normal file
306
README.md
Normal file
@ -0,0 +1,306 @@
|
||||
# Create a GitHub Action Using TypeScript
|
||||
|
||||
[](https://github.com/super-linter/super-linter)
|
||||

|
||||
[](https://github.com/actions/typescript-action/actions/workflows/check-dist.yml)
|
||||
[](https://github.com/actions/typescript-action/actions/workflows/codeql-analysis.yml)
|
||||
[](./badges/coverage.svg)
|
||||
|
||||
Use this template to bootstrap the creation of a TypeScript action. :rocket:
|
||||
|
||||
This template includes compilation support, tests, a validation workflow,
|
||||
publishing, and versioning guidance.
|
||||
|
||||
If you are new, there's also a simpler introduction in the
|
||||
[Hello world JavaScript action repository](https://github.com/actions/hello-world-javascript-action).
|
||||
|
||||
## Create Your Own Action
|
||||
|
||||
To create your own action, you can use this repository as a template! Just
|
||||
follow the below instructions:
|
||||
|
||||
1. Click the **Use this template** button at the top of the repository
|
||||
1. Select **Create a new repository**
|
||||
1. Select an owner and name for your new repository
|
||||
1. Click **Create repository**
|
||||
1. Clone your new repository
|
||||
|
||||
> [!IMPORTANT]
|
||||
>
|
||||
> Make sure to remove or update the [`CODEOWNERS`](./CODEOWNERS) file! For
|
||||
> details on how to use this file, see
|
||||
> [About code owners](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners).
|
||||
|
||||
## Initial Setup
|
||||
|
||||
After you've cloned the repository to your local machine or codespace, you'll
|
||||
need to perform some initial setup steps before you can develop your action.
|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> You'll need to have a reasonably modern version of
|
||||
> [Node.js](https://nodejs.org) handy (20.x or later should work!). If you are
|
||||
> using a version manager like [`nodenv`](https://github.com/nodenv/nodenv) or
|
||||
> [`fnm`](https://github.com/Schniz/fnm), this template has a `.node-version`
|
||||
> file at the root of the repository that can be used to automatically switch to
|
||||
> the correct version when you `cd` into the repository. Additionally, this
|
||||
> `.node-version` file is used by GitHub Actions in any `actions/setup-node`
|
||||
> actions.
|
||||
|
||||
1. :hammer_and_wrench: Install the dependencies
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
1. :building_construction: Package the TypeScript for distribution
|
||||
|
||||
```bash
|
||||
npm run bundle
|
||||
```
|
||||
|
||||
1. :white_check_mark: Run the tests
|
||||
|
||||
```bash
|
||||
$ npm test
|
||||
|
||||
PASS ./index.test.js
|
||||
✓ throws invalid number (3ms)
|
||||
✓ wait 500 ms (504ms)
|
||||
✓ test runs (95ms)
|
||||
|
||||
...
|
||||
```
|
||||
|
||||
## Update the Action Metadata
|
||||
|
||||
The [`action.yml`](action.yml) file defines metadata about your action, such as
|
||||
input(s) and output(s). For details about this file, see
|
||||
[Metadata syntax for GitHub Actions](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions).
|
||||
|
||||
When you copy this repository, update `action.yml` with the name, description,
|
||||
inputs, and outputs for your action.
|
||||
|
||||
## Update the Action Code
|
||||
|
||||
The [`src/`](./src/) directory is the heart of your action! This contains the
|
||||
source code that will be run when your action is invoked. You can replace the
|
||||
contents of this directory with your own code.
|
||||
|
||||
There are a few things to keep in mind when writing your action code:
|
||||
|
||||
- Most GitHub Actions toolkit and CI/CD operations are processed asynchronously.
|
||||
In `main.ts`, you will see that the action is run in an `async` function.
|
||||
|
||||
```javascript
|
||||
import * as core from '@actions/core'
|
||||
//...
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
//...
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For more information about the GitHub Actions toolkit, see the
|
||||
[documentation](https://github.com/actions/toolkit/blob/master/README.md).
|
||||
|
||||
So, what are you waiting for? Go ahead and start customizing your action!
|
||||
|
||||
1. Create a new branch
|
||||
|
||||
```bash
|
||||
git checkout -b releases/v1
|
||||
```
|
||||
|
||||
1. Replace the contents of `src/` with your action code
|
||||
1. Add tests to `__tests__/` for your source code
|
||||
1. Format, test, and build the action
|
||||
|
||||
```bash
|
||||
npm run all
|
||||
```
|
||||
|
||||
> This step is important! It will run [`rollup`](https://rollupjs.org/) to
|
||||
> build the final JavaScript action code with all dependencies included. If
|
||||
> you do not run this step, your action will not work correctly when it is
|
||||
> used in a workflow.
|
||||
|
||||
1. (Optional) Test your action locally
|
||||
|
||||
The [`@github/local-action`](https://github.com/github/local-action) utility
|
||||
can be used to test your action locally. It is a simple command-line tool
|
||||
that "stubs" (or simulates) the GitHub Actions Toolkit. This way, you can run
|
||||
your TypeScript action locally without having to commit and push your changes
|
||||
to a repository.
|
||||
|
||||
The `local-action` utility can be run in the following ways:
|
||||
|
||||
- Visual Studio Code Debugger
|
||||
|
||||
Make sure to review and, if needed, update
|
||||
[`.vscode/launch.json`](./.vscode/launch.json)
|
||||
|
||||
- Terminal/Command Prompt
|
||||
|
||||
```bash
|
||||
# npx @github/local action <action-yaml-path> <entrypoint> <dotenv-file>
|
||||
npx @github/local-action . src/main.ts .env
|
||||
```
|
||||
|
||||
You can provide a `.env` file to the `local-action` CLI to set environment
|
||||
variables used by the GitHub Actions Toolkit. For example, setting inputs and
|
||||
event payload data used by your action. For more information, see the example
|
||||
file, [`.env.example`](./.env.example), and the
|
||||
[GitHub Actions Documentation](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables).
|
||||
|
||||
1. Commit your changes
|
||||
|
||||
```bash
|
||||
git add .
|
||||
git commit -m "My first action is ready!"
|
||||
```
|
||||
|
||||
1. Push them to your repository
|
||||
|
||||
```bash
|
||||
git push -u origin releases/v1
|
||||
```
|
||||
|
||||
1. Create a pull request and get feedback on your action
|
||||
1. Merge the pull request into the `main` branch
|
||||
|
||||
Your action is now published! :rocket:
|
||||
|
||||
For information about versioning your action, see
|
||||
[Versioning](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
|
||||
in the GitHub Actions toolkit.
|
||||
|
||||
## Validate the Action
|
||||
|
||||
You can now validate the action by referencing it in a workflow file. For
|
||||
example, [`ci.yml`](./.github/workflows/ci.yml) demonstrates how to reference an
|
||||
action in the same repository.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: Checkout
|
||||
id: checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Test Local Action
|
||||
id: test-action
|
||||
uses: ./
|
||||
with:
|
||||
milliseconds: 1000
|
||||
|
||||
- name: Print Output
|
||||
id: output
|
||||
run: echo "${{ steps.test-action.outputs.time }}"
|
||||
```
|
||||
|
||||
For example workflow runs, check out the
|
||||
[Actions tab](https://github.com/actions/typescript-action/actions)! :rocket:
|
||||
|
||||
## Usage
|
||||
|
||||
After testing, you can create version tag(s) that developers can use to
|
||||
reference different stable versions of your action. For more information, see
|
||||
[Versioning](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
|
||||
in the GitHub Actions toolkit.
|
||||
|
||||
To include the action in a workflow in another repository, you can use the
|
||||
`uses` syntax with the `@` symbol to reference a specific branch, tag, or commit
|
||||
hash.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: Checkout
|
||||
id: checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Test Local Action
|
||||
id: test-action
|
||||
uses: actions/typescript-action@v1 # Commit with the `v1` tag
|
||||
with:
|
||||
milliseconds: 1000
|
||||
|
||||
- name: Print Output
|
||||
id: output
|
||||
run: echo "${{ steps.test-action.outputs.time }}"
|
||||
```
|
||||
|
||||
## Publishing a New Release
|
||||
|
||||
This project includes a helper script, [`script/release`](./script/release)
|
||||
designed to streamline the process of tagging and pushing new releases for
|
||||
GitHub Actions.
|
||||
|
||||
GitHub Actions allows users to select a specific version of the action to use,
|
||||
based on release tags. This script simplifies this process by performing the
|
||||
following steps:
|
||||
|
||||
1. **Retrieving the latest release tag:** The script starts by fetching the most
|
||||
recent SemVer release tag of the current branch, by looking at the local data
|
||||
available in your repository.
|
||||
1. **Prompting for a new release tag:** The user is then prompted to enter a new
|
||||
release tag. To assist with this, the script displays the tag retrieved in
|
||||
the previous step, and validates the format of the inputted tag (vX.X.X). The
|
||||
user is also reminded to update the version field in package.json.
|
||||
1. **Tagging the new release:** The script then tags a new release and syncs the
|
||||
separate major tag (e.g. v1, v2) with the new release tag (e.g. v1.0.0,
|
||||
v2.1.2). When the user is creating a new major release, the script
|
||||
auto-detects this and creates a `releases/v#` branch for the previous major
|
||||
version.
|
||||
1. **Pushing changes to remote:** Finally, the script pushes the necessary
|
||||
commits, tags and branches to the remote repository. From here, you will need
|
||||
to create a new release in GitHub so users can easily reference the new tags
|
||||
in their workflows.
|
||||
|
||||
## Dependency License Management
|
||||
|
||||
This template includes a GitHub Actions workflow,
|
||||
[`licensed.yml`](./.github/workflows/licensed.yml), that uses
|
||||
[Licensed](https://github.com/licensee/licensed) to check for dependencies with
|
||||
missing or non-compliant licenses. This workflow is initially disabled. To
|
||||
enable the workflow, follow the below steps.
|
||||
|
||||
1. Open [`licensed.yml`](./.github/workflows/licensed.yml)
|
||||
1. Uncomment the following lines:
|
||||
|
||||
```yaml
|
||||
# pull_request:
|
||||
# branches:
|
||||
# - main
|
||||
# push:
|
||||
# branches:
|
||||
# - main
|
||||
```
|
||||
|
||||
1. Save and commit the changes
|
||||
|
||||
Once complete, this workflow will run any time a pull request is created or
|
||||
changes pushed directly to `main`. If the workflow detects any dependencies with
|
||||
missing or non-compliant licenses, it will fail the workflow and provide details
|
||||
on the issue(s) found.
|
||||
|
||||
### Updating Licenses
|
||||
|
||||
Whenever you install or update dependencies, you can use the Licensed CLI to
|
||||
update the licenses database. To install Licensed, see the project's
|
||||
[Readme](https://github.com/licensee/licensed?tab=readme-ov-file#installation).
|
||||
|
||||
To update the cached licenses, run the following command:
|
||||
|
||||
```bash
|
||||
licensed cache
|
||||
```
|
||||
|
||||
To check the status of cached licenses, run the following command:
|
||||
|
||||
```bash
|
||||
licensed status
|
||||
```
|
||||
14
action.yml
Normal file
14
action.yml
Normal file
@ -0,0 +1,14 @@
|
||||
name: deploy-image
|
||||
description: Deploy Image To K8s
|
||||
author: SongHuWanKj
|
||||
|
||||
# Define your inputs here.
|
||||
inputs:
|
||||
image:
|
||||
description: Deploy Image Url
|
||||
required: true
|
||||
default: ''
|
||||
|
||||
runs:
|
||||
using: node20
|
||||
main: dist/index.js
|
||||
27293
dist/index.js
generated
vendored
Normal file
27293
dist/index.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/index.js.map
generated
vendored
Normal file
1
dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
81
eslint.config.mjs
Normal file
81
eslint.config.mjs
Normal file
@ -0,0 +1,81 @@
|
||||
// See: https://eslint.org/docs/latest/use/configure/configuration-files
|
||||
|
||||
import { fixupPluginRules } from '@eslint/compat'
|
||||
import { FlatCompat } from '@eslint/eslintrc'
|
||||
import js from '@eslint/js'
|
||||
import typescriptEslint from '@typescript-eslint/eslint-plugin'
|
||||
import tsParser from '@typescript-eslint/parser'
|
||||
import _import from 'eslint-plugin-import'
|
||||
import jest from 'eslint-plugin-jest'
|
||||
import prettier from 'eslint-plugin-prettier'
|
||||
import globals from 'globals'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: __dirname,
|
||||
recommendedConfig: js.configs.recommended,
|
||||
allConfig: js.configs.all
|
||||
})
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: ['**/coverage', '**/dist', '**/linter', '**/node_modules']
|
||||
},
|
||||
...compat.extends(
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:jest/recommended',
|
||||
'plugin:prettier/recommended'
|
||||
),
|
||||
{
|
||||
plugins: {
|
||||
import: fixupPluginRules(_import),
|
||||
jest,
|
||||
prettier,
|
||||
'@typescript-eslint': typescriptEslint
|
||||
},
|
||||
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.jest,
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
|
||||
parser: tsParser,
|
||||
ecmaVersion: 2023,
|
||||
sourceType: 'module',
|
||||
|
||||
parserOptions: {
|
||||
project: ['tsconfig.eslint.json'],
|
||||
tsconfigRootDir: '.'
|
||||
}
|
||||
},
|
||||
|
||||
settings: {
|
||||
'import/resolver': {
|
||||
typescript: {
|
||||
alwaysTryTypes: true,
|
||||
project: 'tsconfig.eslint.json'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
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-shadow': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
'prettier/prettier': 'error'
|
||||
}
|
||||
}
|
||||
]
|
||||
40
jest.config.js
Normal file
40
jest.config.js
Normal file
@ -0,0 +1,40 @@
|
||||
// See: https://jestjs.io/docs/configuration
|
||||
|
||||
/** @type {import('ts-jest').JestConfigWithTsJest} **/
|
||||
export default {
|
||||
clearMocks: true,
|
||||
collectCoverage: true,
|
||||
collectCoverageFrom: ['./src/**'],
|
||||
coverageDirectory: './coverage',
|
||||
coveragePathIgnorePatterns: ['/node_modules/', '/dist/'],
|
||||
coverageReporters: ['json-summary', 'text', 'lcov'],
|
||||
// Uncomment the below lines if you would like to enforce a coverage threshold
|
||||
// for your action. This will fail the build if the coverage is below the
|
||||
// specified thresholds.
|
||||
// coverageThreshold: {
|
||||
// global: {
|
||||
// branches: 100,
|
||||
// functions: 100,
|
||||
// lines: 100,
|
||||
// statements: 100
|
||||
// }
|
||||
// },
|
||||
extensionsToTreatAsEsm: ['.ts'],
|
||||
moduleFileExtensions: ['ts', 'js'],
|
||||
preset: 'ts-jest',
|
||||
reporters: ['default'],
|
||||
resolver: 'ts-jest-resolver',
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
|
||||
transform: {
|
||||
'^.+\\.ts$': [
|
||||
'ts-jest',
|
||||
{
|
||||
tsconfig: 'tsconfig.eslint.json',
|
||||
useESM: true
|
||||
}
|
||||
]
|
||||
},
|
||||
verbose: true
|
||||
}
|
||||
11877
package-lock.json
generated
Normal file
11877
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
72
package.json
Normal file
72
package.json
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "typescript-action",
|
||||
"description": "GitHub Actions TypeScript template",
|
||||
"version": "0.0.0",
|
||||
"author": "",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"homepage": "https://github.com/actions/typescript-action",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/actions/typescript-action.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/actions/typescript-action/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"actions"
|
||||
],
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"scripts": {
|
||||
"bundle": "npm run format:write && npm run package",
|
||||
"ci-test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 npx jest",
|
||||
"coverage": "npx make-coverage-badge --output-path ./badges/coverage.svg",
|
||||
"format:write": "npx prettier --write .",
|
||||
"format:check": "npx prettier --check .",
|
||||
"lint": "npx eslint .",
|
||||
"local-action": "npx @github/local-action . src/main.ts .env",
|
||||
"package": "npx rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
|
||||
"package:watch": "npm run package -- --watch",
|
||||
"test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 npx jest",
|
||||
"all": "npm run format:write && npm run lint && npm run test && npm run coverage && npm run package"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
"@kubernetes/client-node": "^1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.2.9",
|
||||
"@github/local-action": "^3.2.1",
|
||||
"@jest/globals": "^29.7.0",
|
||||
"@rollup/plugin-commonjs": "^28.0.1",
|
||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||
"@rollup/plugin-typescript": "^12.1.1",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/node": "^20.17.48",
|
||||
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
||||
"@typescript-eslint/parser": "^8.32.1",
|
||||
"eslint": "^9.27.0",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"eslint-import-resolver-typescript": "^4.3.5",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-jest": "^28.11.0",
|
||||
"eslint-plugin-prettier": "^5.4.0",
|
||||
"jest": "^29.7.0",
|
||||
"make-coverage-badge": "^1.2.0",
|
||||
"prettier": "^3.5.3",
|
||||
"prettier-eslint": "^16.4.2",
|
||||
"rollup": "^4.41.0",
|
||||
"ts-jest": "^29.3.4",
|
||||
"ts-jest-resolver": "^2.0.1",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@rollup/rollup-linux-x64-gnu": "*"
|
||||
}
|
||||
}
|
||||
18
rollup.config.ts
Normal file
18
rollup.config.ts
Normal file
@ -0,0 +1,18 @@
|
||||
// See: https://rollupjs.org/introduction/
|
||||
|
||||
import commonjs from '@rollup/plugin-commonjs'
|
||||
import nodeResolve from '@rollup/plugin-node-resolve'
|
||||
import typescript from '@rollup/plugin-typescript'
|
||||
|
||||
const config = {
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
esModule: true,
|
||||
file: 'dist/index.js',
|
||||
format: 'es',
|
||||
sourcemap: true
|
||||
},
|
||||
plugins: [typescript(), nodeResolve({ preferBuiltins: true }), commonjs()]
|
||||
}
|
||||
|
||||
export default config
|
||||
133
script/release
Executable file
133
script/release
Executable file
@ -0,0 +1,133 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit early
|
||||
# See: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#The-Set-Builtin
|
||||
set -e
|
||||
|
||||
# About:
|
||||
#
|
||||
# This is a helper script to tag and push a new release. GitHub Actions use
|
||||
# release tags to allow users to select a specific version of the action to use.
|
||||
#
|
||||
# See: https://github.com/actions/typescript-action#publishing-a-new-release
|
||||
# See: https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#recommendations
|
||||
#
|
||||
# This script will do the following:
|
||||
#
|
||||
# 1. Retrieve the latest release tag
|
||||
# 2. Display the latest release tag
|
||||
# 3. Prompt the user for a new release tag
|
||||
# 4. Validate the new release tag
|
||||
# 5. Remind user to update the version field in package.json
|
||||
# 6. Tag a new release
|
||||
# 7. Set 'is_major_release' variable
|
||||
# 8. Point separate major release tag (e.g. v1, v2) to the new release
|
||||
# 9. Push the new tags (with commits, if any) to remote
|
||||
# 10. If this is a major release, create a 'releases/v#' branch and push
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# script/release
|
||||
|
||||
# Variables
|
||||
semver_tag_regex='v[0-9]+\.[0-9]+\.[0-9]+$'
|
||||
semver_tag_glob='v[0-9].[0-9].[0-9]*'
|
||||
git_remote='origin'
|
||||
major_semver_tag_regex='\(v[0-9]*\)'
|
||||
|
||||
# Terminal colors
|
||||
OFF='\033[0m'
|
||||
BOLD_RED='\033[1;31m'
|
||||
BOLD_GREEN='\033[1;32m'
|
||||
BOLD_BLUE='\033[1;34m'
|
||||
BOLD_PURPLE='\033[1;35m'
|
||||
BOLD_UNDERLINED='\033[1;4m'
|
||||
BOLD='\033[1m'
|
||||
|
||||
# 1. Retrieve the latest release tag
|
||||
if ! latest_tag=$(git describe --abbrev=0 --match="$semver_tag_glob"); then
|
||||
# There are no existing release tags
|
||||
echo -e "No tags found (yet) - Continue to create and push your first tag"
|
||||
latest_tag="[unknown]"
|
||||
fi
|
||||
|
||||
# 2. Display the latest release tag
|
||||
echo -e "The latest release tag is: ${BOLD_BLUE}${latest_tag}${OFF}"
|
||||
|
||||
# 3. Prompt the user for a new release tag
|
||||
read -r -p 'Enter a new release tag (vX.X.X format): ' new_tag
|
||||
|
||||
# 4. Validate the new release tag
|
||||
if echo "$new_tag" | grep -q -E "$semver_tag_regex"; then
|
||||
# Release tag is valid
|
||||
echo -e "Tag: ${BOLD_BLUE}$new_tag${OFF} is valid syntax"
|
||||
else
|
||||
# Release tag is not in `vX.X.X` format
|
||||
echo -e "Tag: ${BOLD_BLUE}$new_tag${OFF} is ${BOLD_RED}not valid${OFF} (must be in ${BOLD}vX.X.X${OFF} format)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 5. Remind user to update the version field in package.json
|
||||
echo -e -n "Make sure the version field in package.json is ${BOLD_BLUE}$new_tag${OFF}. Yes? [Y/${BOLD_UNDERLINED}n${OFF}] "
|
||||
read -r YN
|
||||
|
||||
if [[ ! ($YN == "y" || $YN == "Y") ]]; then
|
||||
# Package.json version field is not up to date
|
||||
echo -e "Please update the package.json version to ${BOLD_PURPLE}$new_tag${OFF} and commit your changes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 6. Tag a new release
|
||||
git tag "$new_tag" --annotate --message "$new_tag Release"
|
||||
echo -e "Tagged: ${BOLD_GREEN}$new_tag${OFF}"
|
||||
|
||||
# 7. Set 'is_major_release' variable
|
||||
new_major_release_tag=$(expr "$new_tag" : "$major_semver_tag_regex")
|
||||
|
||||
if [[ "$latest_tag" = "[unknown]" ]]; then
|
||||
# This is the first major release
|
||||
is_major_release='yes'
|
||||
else
|
||||
# Compare the major version of the latest tag with the new tag
|
||||
latest_major_release_tag=$(expr "$latest_tag" : "$major_semver_tag_regex")
|
||||
|
||||
if ! [[ "$new_major_release_tag" = "$latest_major_release_tag" ]]; then
|
||||
is_major_release='yes'
|
||||
else
|
||||
is_major_release='no'
|
||||
fi
|
||||
fi
|
||||
|
||||
# 8. Point separate major release tag (e.g. v1, v2) to the new release
|
||||
if [ $is_major_release = 'yes' ]; then
|
||||
# Create a new major version tag and point it to this release
|
||||
git tag "$new_major_release_tag" --annotate --message "$new_major_release_tag Release"
|
||||
echo -e "New major version tag: ${BOLD_GREEN}$new_major_release_tag${OFF}"
|
||||
else
|
||||
# Update the major version tag to point it to this release
|
||||
git tag "$latest_major_release_tag" --force --annotate --message "Sync $latest_major_release_tag tag with $new_tag"
|
||||
echo -e "Synced ${BOLD_GREEN}$latest_major_release_tag${OFF} with ${BOLD_GREEN}$new_tag${OFF}"
|
||||
fi
|
||||
|
||||
# 9. Push the new tags (with commits, if any) to remote
|
||||
git push --follow-tags
|
||||
|
||||
if [ $is_major_release = 'yes' ]; then
|
||||
# New major version tag is pushed with the '--follow-tags' flags
|
||||
echo -e "Tags: ${BOLD_GREEN}$new_major_release_tag${OFF} and ${BOLD_GREEN}$new_tag${OFF} pushed to remote"
|
||||
else
|
||||
# Force push the updated major version tag
|
||||
git push $git_remote "$latest_major_release_tag" --force
|
||||
echo -e "Tags: ${BOLD_GREEN}$latest_major_release_tag${OFF} and ${BOLD_GREEN}$new_tag${OFF} pushed to remote"
|
||||
fi
|
||||
|
||||
# 10. If this is a major release, create a 'releases/v#' branch and push
|
||||
if [ $is_major_release = 'yes' ]; then
|
||||
git branch "releases/$new_major_release_tag" "$new_major_release_tag"
|
||||
echo -e "Branch: ${BOLD_BLUE}releases/$new_major_release_tag${OFF} created from ${BOLD_BLUE}$new_major_release_tag${OFF} tag"
|
||||
git push --set-upstream $git_remote "releases/$new_major_release_tag"
|
||||
echo -e "Branch: ${BOLD_GREEN}releases/$new_major_release_tag${OFF} pushed to remote"
|
||||
fi
|
||||
|
||||
# Completed
|
||||
echo -e "${BOLD_GREEN}Done!${OFF}"
|
||||
8
src/index.ts
Normal file
8
src/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* The entrypoint for the action. This file simply imports and runs the action's
|
||||
* main logic.
|
||||
*/
|
||||
import { run } from './main.js'
|
||||
|
||||
/* istanbul ignore next */
|
||||
run()
|
||||
27
src/main.ts
Normal file
27
src/main.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import * as core from '@actions/core'
|
||||
import { wait } from './wait.js'
|
||||
|
||||
/**
|
||||
* The main function for the action.
|
||||
*
|
||||
* @returns Resolves when the action is complete.
|
||||
*/
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const ms: string = core.getInput('milliseconds')
|
||||
|
||||
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
|
||||
core.debug(`Waiting ${ms} milliseconds ...`)
|
||||
|
||||
// Log the current timestamp, wait, then log the new timestamp
|
||||
core.debug(new Date().toTimeString())
|
||||
await wait(parseInt(ms, 10))
|
||||
core.debug(new Date().toTimeString())
|
||||
|
||||
// Set outputs for other workflow steps to use
|
||||
core.setOutput('time', new Date().toTimeString())
|
||||
} catch (error) {
|
||||
// Fail the workflow run if an error occurs
|
||||
if (error instanceof Error) core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
13
src/wait.ts
Normal file
13
src/wait.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Waits for a number of milliseconds.
|
||||
*
|
||||
* @param milliseconds The number of milliseconds to wait.
|
||||
* @returns Resolves with 'done!' after the wait is over.
|
||||
*/
|
||||
export async function wait(milliseconds: number): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
if (isNaN(milliseconds)) throw new Error('milliseconds is not a number')
|
||||
|
||||
setTimeout(() => resolve('done!'), milliseconds)
|
||||
})
|
||||
}
|
||||
22
tsconfig.base.json
Normal file
22
tsconfig.base.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"lib": ["ES2022"],
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"newLine": "lf",
|
||||
"noImplicitAny": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": false,
|
||||
"pretty": true,
|
||||
"resolveJsonModule": true,
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"target": "ES2022"
|
||||
}
|
||||
}
|
||||
17
tsconfig.eslint.json
Normal file
17
tsconfig.eslint.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"exclude": ["dist", "node_modules"],
|
||||
"include": [
|
||||
"__fixtures__",
|
||||
"__tests__",
|
||||
"src",
|
||||
"eslint.config.mjs",
|
||||
"jest.config.js",
|
||||
"rollup.config.ts"
|
||||
]
|
||||
}
|
||||
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["__fixtures__", "__tests__", "coverage", "dist", "node_modules"],
|
||||
"include": ["src"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user