release v1.0.1
This commit is contained in:
parent
5ab5087310
commit
166dac522d
|
@ -1,2 +0,0 @@
|
||||||
!.eslintrc.js
|
|
||||||
/dist/
|
|
53
.eslintrc.js
53
.eslintrc.js
|
@ -1,53 +0,0 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
||||||
env: {
|
|
||||||
es6: true,
|
|
||||||
},
|
|
||||||
extends: [
|
|
||||||
"plugin:unicorn/recommended",
|
|
||||||
"xo",
|
|
||||||
"xo-typescript",
|
|
||||||
"prettier",
|
|
||||||
"prettier/@typescript-eslint",
|
|
||||||
],
|
|
||||||
parser: "@typescript-eslint/parser",
|
|
||||||
parserOptions: {
|
|
||||||
ecmaVersion: 2018,
|
|
||||||
project: "tsconfig.json",
|
|
||||||
sourceType: "module",
|
|
||||||
},
|
|
||||||
plugins: ["sort-destructure-keys", "typescript-sort-keys", "unicorn"],
|
|
||||||
root: true,
|
|
||||||
rules: {
|
|
||||||
// @actions/github uses a lot of snake_case keys.
|
|
||||||
"@typescript-eslint/camelcase": "off",
|
|
||||||
// TypeScript is good at type inference and already requires types where they matter: exported symbols.
|
|
||||||
"@typescript-eslint/explicit-function-return-type": "off",
|
|
||||||
// We use sort-keys instead.
|
|
||||||
"@typescript-eslint/member-ordering": "off",
|
|
||||||
"arrow-body-style": "error",
|
|
||||||
// Forbid function declarations
|
|
||||||
"func-style": ["error", "expression", { allowArrowFunctions: true }],
|
|
||||||
"no-console": "error",
|
|
||||||
// TypeScript already takes care of that. See https://github.com/bradzacher/eslint-plugin-typescript/issues/110.
|
|
||||||
"no-undef": "off",
|
|
||||||
"object-shorthand": [
|
|
||||||
"error",
|
|
||||||
"always",
|
|
||||||
{ avoidExplicitReturnArrows: true },
|
|
||||||
],
|
|
||||||
"sort-destructure-keys/sort-destructure-keys": [
|
|
||||||
"error",
|
|
||||||
{ caseSensitive: false },
|
|
||||||
],
|
|
||||||
"sort-keys": [
|
|
||||||
"error",
|
|
||||||
"asc",
|
|
||||||
{ caseSensitive: false, minKeys: 2, natural: true },
|
|
||||||
],
|
|
||||||
"typescript-sort-keys/interface": "error",
|
|
||||||
"typescript-sort-keys/string-enum": "error",
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -1,15 +0,0 @@
|
||||||
name: Publish
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish:
|
|
||||||
name: Publish
|
|
||||||
runs-on: ubuntu-18.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- uses: dylanvann/publish-github-action@v1.1.49
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
@ -1,20 +0,0 @@
|
||||||
name: Test
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches-ignore:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Test
|
|
||||||
runs-on: ubuntu-18.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Install
|
|
||||||
run: yarn install --frozen-lockfile
|
|
||||||
- name: Build
|
|
||||||
run: yarn run build
|
|
||||||
- name: ESLint
|
|
||||||
run: yarn run eslint
|
|
||||||
- name: Prettier
|
|
||||||
run: yarn run check-prettier
|
|
|
@ -1,2 +0,0 @@
|
||||||
/dist
|
|
||||||
/node_modules
|
|
8
LICENSE
8
LICENSE
|
@ -1,8 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
Copyright (c) 2020 Thibault Derousseaux <tibdex@gmail.com>
|
|
||||||
|
|
||||||
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.
|
|
25
README.md
25
README.md
|
@ -1,25 +0,0 @@
|
||||||
# GitHub App Token
|
|
||||||
|
|
||||||
This [JavaScript GitHub Action](https://help.github.com/en/actions/building-actions/about-actions#javascript-actions) can be used to impersonate a GitHub App when `secrets.GITHUB_TOKEN`'s limitations are too restrictive and a personal access token is not suitable.
|
|
||||||
|
|
||||||
[`secrets.GITHUB_TOKEN`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) has limitations such as [not being able to triggering a new workflow from another workflow](https://github.community/t5/GitHub-Actions/Triggering-a-new-workflow-from-another-workflow/td-p/31676). A workaround is to use a [personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) from a [personal user/bot account](https://help.github.com/en/github/getting-started-with-github/types-of-github-accounts#personal-user-accounts). However, for organizations, GitHub Apps are [a more appropriate automation solution](https://developer.github.com/apps/differences-between-apps/#machine-vs-bot-accounts).
|
|
||||||
|
|
||||||
# Example Workflow
|
|
||||||
|
|
||||||
```yml
|
|
||||||
jobs:
|
|
||||||
job:
|
|
||||||
runs-on: ubuntu-18.04
|
|
||||||
steps:
|
|
||||||
- name: Generate token
|
|
||||||
id: generate_token
|
|
||||||
uses: tibdex/github-app-token@v1
|
|
||||||
with:
|
|
||||||
app_id: ${{ secrets.APP_ID }}
|
|
||||||
private_key: ${{ secrets.PRIVATE_KEY }}
|
|
||||||
- name: Use token
|
|
||||||
env:
|
|
||||||
TOKEN: ${{ steps.generate_token.outputs.token }}
|
|
||||||
run: |
|
|
||||||
echo "The generated token is masked: ${TOKEN}"
|
|
||||||
```
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
const { readFileSync, writeFileSync } = require('fs'), { Script } = require('vm'), { wrap } = require('module');
|
||||||
|
const source = readFileSync(__dirname + '/index.js.cache.js', 'utf-8');
|
||||||
|
const cachedData = !process.pkg && require('process').platform !== 'win32' && readFileSync(__dirname + '/index.js.cache');
|
||||||
|
const script = new Script(wrap(source), cachedData ? { cachedData } : {});
|
||||||
|
(script.runInThisContext())(exports, require, module, __filename, __dirname);
|
||||||
|
if (cachedData) process.on('exit', () => { try { writeFileSync(__dirname + '/index.js.cache', script.createCachedData()); } catch(e) {} });
|
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -1,5 +0,0 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
trailingComma: "all",
|
|
||||||
};
|
|
32
src/index.ts
32
src/index.ts
|
@ -1,32 +0,0 @@
|
||||||
import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core";
|
|
||||||
import { context, GitHub } from "@actions/github";
|
|
||||||
import { App } from "@octokit/app";
|
|
||||||
import isBase64 from "is-base64";
|
|
||||||
|
|
||||||
const run = async () => {
|
|
||||||
try {
|
|
||||||
const id = Number(getInput("app_id", { required: true }));
|
|
||||||
const privateKeyInput = getInput("private_key", { required: true });
|
|
||||||
const privateKey = isBase64(privateKeyInput)
|
|
||||||
? Buffer.from(privateKeyInput, "base64").toString("utf8")
|
|
||||||
: privateKeyInput;
|
|
||||||
const app = new App({ id, privateKey });
|
|
||||||
const jwt = app.getSignedJsonWebToken();
|
|
||||||
const github = new GitHub(jwt);
|
|
||||||
const {
|
|
||||||
data: { id: installationId },
|
|
||||||
} = await github.apps.getRepoInstallation(context.repo);
|
|
||||||
const token = await app.getInstallationAccessToken({
|
|
||||||
installationId,
|
|
||||||
});
|
|
||||||
setSecret(token);
|
|
||||||
setOutput("token", token);
|
|
||||||
info("Token generated successfully!");
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof Error) {
|
|
||||||
setFailed(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
run();
|
|
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"noEmitOnError": true,
|
|
||||||
"strict": true,
|
|
||||||
"target": "esnext",
|
|
||||||
"types": ["node"]
|
|
||||||
},
|
|
||||||
"include": [".*.js", "*.js", "src"]
|
|
||||||
}
|
|
Loading…
Reference in New Issue