diff --git a/.eslintrc.json b/.eslintrc.json index 1a8e951..950dd3c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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 - } - } \ No newline at end of file + "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 + } +} \ No newline at end of file diff --git a/README.md b/README.md index ef73fbb..18a4f30 100644 --- a/README.md +++ b/README.md @@ -1,103 +1,16 @@

- typescript-action status + update-winget status

-# 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 diff --git a/action.yml b/action.yml index bfbb165..cfda423 100644 --- a/action.yml +++ b/action.yml @@ -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 '/'. + 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 diff --git a/package-lock.json b/package-lock.json index c1b67c4..dd99c18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "typescript-action", + "name": "update-winget", "version": "0.0.0", "lockfileVersion": 1, "requires": true, diff --git a/package.json b/package.json index 722c016..c435b3b 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/main.ts b/src/main.ts index c1574d0..e23fd4f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,16 +1,7 @@ import * as core from '@actions/core' -import {wait} from './wait' async function run(): Promise { 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) } diff --git a/src/wait.ts b/src/wait.ts deleted file mode 100644 index b169d9a..0000000 --- a/src/wait.ts +++ /dev/null @@ -1,9 +0,0 @@ -export async function wait(milliseconds: number): Promise { - return new Promise(resolve => { - if (isNaN(milliseconds)) { - throw new Error('milliseconds not a number') - } - - setTimeout(() => resolve('done!'), milliseconds) - }) -}