diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7230259..4cad037 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: node-version: 20 cache: npm - run: npm ci - # - run: npm run typecheck + - run: npm run typecheck - run: npm run build # Optional integration test of the action using a dedicated GitHub App. - id: create_token @@ -25,6 +25,7 @@ jobs: # The only required permission is `Repository permissions > Metadata: Read-only`. app_id: ${{ vars.TEST_GITHUB_APP_ID }} private_key: ${{ secrets.TEST_GITHUB_APP_PRIVATE_KEY }} + revoke: false - if: ${{ steps.create_token.outcome != 'skipped' }} run: node --eval "assert('${{ steps.create_token.outputs.token }}'.length > 0);" - # - run: npm run prettier -- --check + - run: npm run prettier -- --check diff --git a/action.yml b/action.yml index 0cda016..407c8a8 100644 --- a/action.yml +++ b/action.yml @@ -51,7 +51,6 @@ runs: using: node20 main: dist/main/index.js post: dist/post/index.js - post-if: inputs.revoke == 'true' branding: icon: unlock color: gray-dark diff --git a/package.json b/package.json index 0a44813..f05683a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dist" ], "scripts": { - "build": "npm run build:main", + "build": "npm run build:main && npm run build:post", "build:main": "npm run compile -- --out ./dist/main src/main.ts ", "build:post": "npm run compile -- --out ./dist/post src/post.ts", "compile": "ncc build --minify --no-cache --target es2022 --v8-cache", diff --git a/src/main.ts b/src/main.ts index 08ee582..9a0f7f2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,15 @@ +import { info, saveState, setOutput, setSecret } from "@actions/core"; +import { createInstallationAccessToken } from "./create-installation-access-token.js"; +import { parseOptions } from "./parse-options.js"; import { run } from "./run.js"; -import { getInput } from "@actions/core"; +import { tokenKey } from "./state.js"; await run(async () => { - console.log(JSON.stringify({value: JSON.parse(getInput("revoke"))})); + const options = parseOptions(); + const token = await createInstallationAccessToken(options); + setSecret(token); + saveState(tokenKey, token); + setOutput("token", token); + info("Token created successfully"); }); diff --git a/src/post.ts b/src/post.ts index 9ffc13c..0d2680e 100644 --- a/src/post.ts +++ b/src/post.ts @@ -1,10 +1,15 @@ -import { getState, info } from "@actions/core"; +import { getInput, getState, info } from "@actions/core"; import { revokeInstallationAccessToken } from "./revoke-installation-access-token.js"; import { run } from "./run.js"; import { tokenKey } from "./state.js"; await run(async () => { + if (!JSON.parse(getInput("revoke"))) { + info("Token revocation skipped"); + return; + } + const token = getState(tokenKey); if (!token) { info("No token to revoke");