Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
init: replace template code and docs
Browse files Browse the repository at this point in the history
Replace template code and documentation with real project name.
  • Loading branch information
mjcheetham committed Oct 5, 2020
1 parent 88a4230 commit 42f7e2a
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 178 deletions.
106 changes: 53 additions & 53 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@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-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "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",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@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-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "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",
"semi": "off",
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
105 changes: 9 additions & 96 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,16 @@
<p align="center">
<a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a>
<a href="https://github.com/mjcheetham/update-winget/actions"><img alt="update-winget status" src="https://github.com/mjcheetham/update-winget/workflows/build-test/badge.svg"></a>
</p>

# Create a JavaScript Action using TypeScript
Update a Windows Package (`winget`) from a workflow.

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. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)

## Create an action from this template

Click the `Use this Template` and provide the new repo details for your action

## Code in Main

Install the dependencies
```bash
$ npm install
```

Build the typescript and package it for distribution
```bash
$ npm run build && npm run package
```

Run the tests :heavy_check_mark:
```bash
$ npm test

PASS ./index.test.js
✓ throws invalid number (3ms)
wait 500 ms (504ms)
test runs (95ms)

...
```

## Change action.yml

The action.yml contains defines the inputs and output for your action.

Update the action.yml with your name, description, inputs and outputs for your action.

See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)

## Change the Code

Most toolkit and CI/CD operations involve async operations so 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);
}
}

run()
```

See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.

## Publish to a distribution branch

Actions are run from GitHub repos so we will checkin the packed dist folder.

Then run [ncc](https://github.com/zeit/ncc) and push the results:
```bash
$ npm run package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
```

Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.

Your action is now published! :rocket:

See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)

## Validate

You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))
## Example

```yaml
uses: ./
with:
milliseconds: 1000
- uses: mjcheetham/update-winget@v1
with:
token: ${{secrets.COMMIT_TOKEN}}
id: My.Package
version: 2.3.4
sha256: e99fa5e39fa055c318300f65353c8256fca7cc25c16212c73da2081c5a3637f7
```
See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket:
## Usage:
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action
76 changes: 70 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,75 @@
name: 'Your name here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: update-winget
description: Update a winget manifest with new version information.
author: mjcheetham
inputs:
milliseconds: # change this
id:
description: Manifest ID
required: true
description: 'input description here'
default: 'default value if applicable'
version:
description: |
Manifest version. Required if 'releaseRepo', 'releaseTag', and 'releaseAsset' are not specified.
required: false
releaseRepo:
description: |
Repository from which to locate a release asset to compute the new manifest version.
If not provided `GITHUB_REPOSITORY` (the current repository) is used as the default.
required: false
releaseTag:
description: |
Tag for the release containing an asset from which to compute the new manifest verison.
If not provided `GITHUB_REF` (the current ref) is used as the default.
required: false
releaseAsset:
description: |
Regular expression to match release asset names for updating the manifest version.
Must contain one capture group that captures the new manifest version number. If a named capture
group 'version' exists that will be used, otherwise the first capture group (matches[1]) will
be used.
required: false
url:
description: |
Download asset URL. The following replacements will be made:
{{version}} => full version string
{{version.major}} => major version (x)
{{version.major_minor}} => major and minor version (x.y)
{{version.major_minor_patch}} => major, minor and patch version (x.y.z)
required: false
sha256:
description: Download asset SHA-256 hash. If omitted the hash will be calculated.
required: false
repo:
description: |
Repository to update. Must be in the form '<org>/<name>'.
Defaults to 'microsoft/winget-pkgs'.
required: false
default: microsoft/winget-pkgs
branch:
description: Repository branch to target. Defaults to the default branch.
required: false
token:
description: Access token used to access the repository, submit pull requests or push commits.
required: true
message:
description: |
Commit message template for the update. The following replacements will be made:
{{id}} => ID of the package
{{file}} => file path of the manifest
{{version}} => full version string
{{version.major}} => major version (x)
{{version.major_minor}} => major and minor version (x.y)
{{version.major_minor_patch}} => major, minor and patch version (x.y.z)
required: false
default: |
{{id}}: update to {{version}}
alwaysUsePullRequest:
description: |
Set to 'true' to always create a pull request rather than committing directly
to the repository's branch, even if it's possible. Defaults to false.
required: false
default: 'false'
runs:
using: 'node12'
main: 'dist/index.js'
branding:
icon: package
color: blue
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "typescript-action",
"name": "update-winget",
"version": "0.0.0",
"private": true,
"description": "TypeScript template action",
"description": "GitHub Action to update winget package manifests.",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
Expand All @@ -15,12 +15,12 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/actions/typescript-action.git"
"url": "git+https://github.com/mjcheetham/update-winget.git"
},
"keywords": [
"actions",
"node",
"setup"
"winget"
],
"author": "",
"license": "MIT",
Expand Down
9 changes: 0 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import * as core from '@actions/core'
import {wait} from './wait'

async function run(): Promise<void> {
try {
const ms: string = core.getInput('milliseconds')
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true

core.debug(new Date().toTimeString())
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())

core.setOutput('time', new Date().toTimeString())
} catch (error) {
core.setFailed(error.message)
}
Expand Down
9 changes: 0 additions & 9 deletions src/wait.ts

This file was deleted.

0 comments on commit 42f7e2a

Please sign in to comment.