Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1a285145b | ||
|
|
fa6118ca85 | ||
|
|
ae140fab7b | ||
|
|
c84b152776 | ||
|
|
26a5f3652e | ||
|
|
6f9957685a | ||
|
|
25cc3bdc27 | ||
|
|
a2c2dfabb4 | ||
|
|
349e62c51a | ||
|
|
5d869da34e | ||
|
|
796b88dc58 | ||
|
|
3378cda945 | ||
|
|
e177c20e0f | ||
|
|
961c2284dc | ||
|
|
15db0371da | ||
|
|
9ccc6dbd71 | ||
|
|
000e2a0d29 | ||
|
|
d0ac2addd1 | ||
|
|
040c2598aa | ||
|
|
31c86eb3b3 | ||
|
|
cc82279e84 | ||
|
|
74cd7f68cb | ||
|
|
ad38cffc07 | ||
|
|
66a7045686 | ||
|
|
d2eeb384df | ||
|
|
0fd38177ed | ||
|
|
b3be847492 | ||
|
|
c8f55efbd4 | ||
|
|
2aec84ed45 | ||
|
|
8d81a59103 | ||
|
|
a0de6af839 | ||
|
|
9d23fb93dd | ||
|
|
3cef845e01 | ||
|
|
7bfa3a4717 | ||
|
|
3c223c7336 | ||
|
|
6c406e8a24 | ||
|
|
beea7b860a | ||
|
|
e982ea3b55 | ||
|
|
34c66235f6 | ||
|
|
78e5f2ddc0 | ||
|
|
d9bc16919c | ||
|
|
f2acddfb51 | ||
|
|
babaff4320 | ||
|
|
bf627a5a44 | ||
|
|
f83fb279aa | ||
|
|
4b73c38a52 | ||
|
|
e8e39f73bb | ||
|
|
1e02bd5721 | ||
|
|
5195df7c88 |
33
.github/dependabot.yml
vendored
33
.github/dependabot.yml
vendored
@@ -1,19 +1,30 @@
|
|||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: "npm"
|
- package-ecosystem: 'npm'
|
||||||
directory: "/"
|
directory: '/'
|
||||||
schedule:
|
schedule:
|
||||||
interval: "monthly"
|
interval: 'monthly'
|
||||||
groups:
|
groups:
|
||||||
production-dependencies:
|
production-dependencies:
|
||||||
dependency-type: "production"
|
dependency-type: 'production'
|
||||||
|
update-types:
|
||||||
|
- minor
|
||||||
|
- patch
|
||||||
development-dependencies:
|
development-dependencies:
|
||||||
dependency-type: "development"
|
dependency-type: 'development'
|
||||||
|
update-types:
|
||||||
|
- minor
|
||||||
|
- patch
|
||||||
commit-message:
|
commit-message:
|
||||||
prefix: "fix"
|
prefix: 'fix'
|
||||||
prefix-development: "build"
|
prefix-development: 'build'
|
||||||
include: "scope"
|
include: 'scope'
|
||||||
- package-ecosystem: "github-actions"
|
- package-ecosystem: 'github-actions'
|
||||||
directory: "/"
|
directory: '/'
|
||||||
schedule:
|
schedule:
|
||||||
interval: "monthly"
|
interval: 'monthly'
|
||||||
|
groups:
|
||||||
|
github-actions:
|
||||||
|
update-types:
|
||||||
|
- minor
|
||||||
|
- patch
|
||||||
|
|||||||
17
.github/workflows/publish-immutable-action.yml
vendored
Normal file
17
.github/workflows/publish-immutable-action.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
name: 'Publish Immutable Action'
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Publish Immutable Action
|
||||||
|
uses: actions/publish-immutable-action@v0.0.4
|
||||||
1
.github/workflows/test.yml
vendored
1
.github/workflows/test.yml
vendored
@@ -5,6 +5,7 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|||||||
127
README.md
127
README.md
@@ -12,6 +12,9 @@ In order to use this action, you need to:
|
|||||||
2. [Store the App's ID in your repository environment variables](https://docs.github.com/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows) (example: `APP_ID`)
|
2. [Store the App's ID in your repository environment variables](https://docs.github.com/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows) (example: `APP_ID`)
|
||||||
3. [Store the App's private key in your repository secrets](https://docs.github.com/actions/security-guides/encrypted-secrets?tool=webui#creating-encrypted-secrets-for-a-repository) (example: `PRIVATE_KEY`)
|
3. [Store the App's private key in your repository secrets](https://docs.github.com/actions/security-guides/encrypted-secrets?tool=webui#creating-encrypted-secrets-for-a-repository) (example: `PRIVATE_KEY`)
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> An installation access token expires after 1 hour. Please [see this comment](https://github.com/actions/create-github-app-token/issues/121#issuecomment-2043214796) for alternative approaches if you have long-running processes.
|
||||||
|
|
||||||
### Create a token for the current repository
|
### Create a token for the current repository
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -30,7 +33,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
app-id: ${{ vars.APP_ID }}
|
app-id: ${{ vars.APP_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
github-api-url: "https://github.acme-inc.com/api/v3"
|
|
||||||
- uses: ./actions/staging-tests
|
- uses: ./actions/staging-tests
|
||||||
with:
|
with:
|
||||||
token: ${{ steps.app-token.outputs.token }}
|
token: ${{ steps.app-token.outputs.token }}
|
||||||
@@ -62,6 +64,68 @@ jobs:
|
|||||||
github_token: ${{ steps.app-token.outputs.token }}
|
github_token: ${{ steps.app-token.outputs.token }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Create a git committer string for an app installation
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
auto-format:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/create-github-app-token@v1
|
||||||
|
id: app-token
|
||||||
|
with:
|
||||||
|
# required
|
||||||
|
app-id: ${{ vars.APP_ID }}
|
||||||
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
|
- name: Get GitHub App User ID
|
||||||
|
id: get-user-id
|
||||||
|
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||||
|
- id: committer
|
||||||
|
run: echo "string=${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>" >> "$GITHUB_OUTPUT"
|
||||||
|
- run: echo "committer string is ${ {steps.committer.outputs.string }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configure git CLI for an app's bot user
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
auto-format:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/create-github-app-token@v1
|
||||||
|
id: app-token
|
||||||
|
with:
|
||||||
|
# required
|
||||||
|
app-id: ${{ vars.APP_ID }}
|
||||||
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
|
- name: Get GitHub App User ID
|
||||||
|
id: get-user-id
|
||||||
|
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||||
|
- run: |
|
||||||
|
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
|
||||||
|
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
|
||||||
|
# git commands like commit work using the bot user
|
||||||
|
- run: |
|
||||||
|
git add .
|
||||||
|
git commit -m "Auto-generated changes"
|
||||||
|
git push
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
> The `<BOT USER ID>` is the numeric user ID of the app's bot user, which can be found under `https://api.github.com/users/<app-slug>%5Bbot%5D`.
|
||||||
|
>
|
||||||
|
> For example, we can check at `https://api.github.com/users/dependabot[bot]` to see the user ID of Dependabot is 49699333.
|
||||||
|
>
|
||||||
|
> Alternatively, you can use the [octokit/request-action](https://github.com/octokit/request-action) to get the ID.
|
||||||
|
|
||||||
### Create a token for all repositories in the current owner's installation
|
### Create a token for all repositories in the current owner's installation
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -99,7 +163,9 @@ jobs:
|
|||||||
app-id: ${{ vars.APP_ID }}
|
app-id: ${{ vars.APP_ID }}
|
||||||
private-key: ${{ secrets.PRIVATE_KEY }}
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
owner: ${{ github.repository_owner }}
|
owner: ${{ github.repository_owner }}
|
||||||
repositories: "repo1,repo2"
|
repositories: |
|
||||||
|
repo1
|
||||||
|
repo2
|
||||||
- uses: peter-evans/create-or-update-comment@v3
|
- uses: peter-evans/create-or-update-comment@v3
|
||||||
with:
|
with:
|
||||||
token: ${{ steps.app-token.outputs.token }}
|
token: ${{ steps.app-token.outputs.token }}
|
||||||
@@ -143,7 +209,7 @@ jobs:
|
|||||||
set-matrix:
|
set-matrix:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
matrix: ${{steps.set.outputs.matrix }}
|
matrix: ${{ steps.set.outputs.matrix }}
|
||||||
steps:
|
steps:
|
||||||
- id: set
|
- id: set
|
||||||
run: echo 'matrix=[{"owner":"owner1"},{"owner":"owner2","repos":["repo1"]}]' >>"$GITHUB_OUTPUT"
|
run: echo 'matrix=[{"owner":"owner1"},{"owner":"owner2","repos":["repo1"]}]' >>"$GITHUB_OUTPUT"
|
||||||
@@ -179,6 +245,29 @@ jobs:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
create_issue:
|
||||||
|
runs-on: self-hosted
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Create GitHub App token
|
||||||
|
id: create_token
|
||||||
|
uses: actions/create-github-app-token@v1
|
||||||
|
with:
|
||||||
|
app-id: ${{ vars.GHES_APP_ID }}
|
||||||
|
private-key: ${{ secrets.GHES_APP_PRIVATE_KEY }}
|
||||||
|
owner: ${{ vars.GHES_INSTALLATION_ORG }}
|
||||||
|
github-api-url: ${{ vars.GITHUB_API_URL }}
|
||||||
|
|
||||||
|
- name: Create issue
|
||||||
|
uses: octokit/request-action@v2.x
|
||||||
|
with:
|
||||||
|
route: POST /repos/${{ github.repository }}/issues
|
||||||
|
title: "New issue from workflow"
|
||||||
|
body: "This is a new issue created from a GitHub Action workflow."
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ steps.create_token.outputs.token }}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
@@ -189,15 +278,33 @@ on: [push]
|
|||||||
|
|
||||||
### `private-key`
|
### `private-key`
|
||||||
|
|
||||||
**Required:** GitHub App private key.
|
**Required:** GitHub App private key. Escaped newlines (`\\n`) will be automatically replaced with actual newlines.
|
||||||
|
|
||||||
|
Some other actions may require the private key to be Base64 encoded. To avoid recreating a new secret, it can be decoded on the fly, but it needs to be managed securely. Here is an example of how this can be achieved:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- name: Decode the GitHub App Private Key
|
||||||
|
id: decode
|
||||||
|
run: |
|
||||||
|
private_key=$(echo "${{ secrets.PRIVATE_KEY }}" | base64 -d | awk 'BEGIN {ORS="\\n"} {print}' | head -c -2) &> /dev/null
|
||||||
|
echo "::add-mask::$private_key"
|
||||||
|
echo "private-key=$private_key" >> "$GITHUB_OUTPUT"
|
||||||
|
- name: Generate GitHub App Token
|
||||||
|
id: app-token
|
||||||
|
uses: actions/create-github-app-token@v1
|
||||||
|
with:
|
||||||
|
app-id: ${{ vars.APP_ID }}
|
||||||
|
private-key: ${{ steps.decode.outputs.private-key }}
|
||||||
|
```
|
||||||
|
|
||||||
### `owner`
|
### `owner`
|
||||||
|
|
||||||
**Optional:** GitHub App installation owner. If empty, defaults to the current repository owner.
|
**Optional:** The owner of the GitHub App installation. If empty, defaults to the current repository owner.
|
||||||
|
|
||||||
### `repositories`
|
### `repositories`
|
||||||
|
|
||||||
**Optional:** Comma-separated list of repositories to grant access to.
|
**Optional:** Comma or newline-separated list of repositories to grant access to.
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> If `owner` is set and `repositories` is empty, access will be scoped to all repositories in the provided repository owner's installation. If `owner` and `repositories` are empty, access will be scoped to only the current repository.
|
> If `owner` is set and `repositories` is empty, access will be scoped to all repositories in the provided repository owner's installation. If `owner` and `repositories` are empty, access will be scoped to only the current repository.
|
||||||
@@ -216,6 +323,14 @@ on: [push]
|
|||||||
|
|
||||||
GitHub App installation access token.
|
GitHub App installation access token.
|
||||||
|
|
||||||
|
### `installation-id`
|
||||||
|
|
||||||
|
GitHub App installation ID.
|
||||||
|
|
||||||
|
### `app-slug`
|
||||||
|
|
||||||
|
GitHub App slug.
|
||||||
|
|
||||||
## How it works
|
## How it works
|
||||||
|
|
||||||
The action creates an installation access token using [the `POST /app/installations/{installation_id}/access_tokens` endpoint](https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app). By default,
|
The action creates an installation access token using [the `POST /app/installations/{installation_id}/access_tokens` endpoint](https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app). By default,
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
deprecationMessage: "'private_key' is deprecated and will be removed in a future version. Use 'private-key' instead."
|
deprecationMessage: "'private_key' is deprecated and will be removed in a future version. Use 'private-key' instead."
|
||||||
owner:
|
owner:
|
||||||
description: "GitHub App owner (defaults to current repository owner)"
|
description: "The owner of the GitHub App installation (defaults to current repository owner)"
|
||||||
required: false
|
required: false
|
||||||
repositories:
|
repositories:
|
||||||
description: "Repositories to install the GitHub App on (defaults to current repository if owner is unset)"
|
description: "Comma or newline-separated list of repositories to install the GitHub App on (defaults to current repository if owner is unset)"
|
||||||
required: false
|
required: false
|
||||||
skip-token-revoke:
|
skip-token-revoke:
|
||||||
description: "If truthy, the token will not be revoked when the current job is complete"
|
description: "If truthy, the token will not be revoked when the current job is complete"
|
||||||
@@ -40,6 +40,10 @@ inputs:
|
|||||||
outputs:
|
outputs:
|
||||||
token:
|
token:
|
||||||
description: "GitHub installation access token"
|
description: "GitHub installation access token"
|
||||||
|
installation-id:
|
||||||
|
description: "GitHub App installation ID"
|
||||||
|
app-slug:
|
||||||
|
description: "GitHub App slug"
|
||||||
runs:
|
runs:
|
||||||
using: "node20"
|
using: "node20"
|
||||||
main: "dist/main.cjs"
|
main: "dist/main.cjs"
|
||||||
|
|||||||
35798
dist/main.cjs
vendored
35798
dist/main.cjs
vendored
File diff suppressed because one or more lines are too long
26815
dist/post.cjs
vendored
26815
dist/post.cjs
vendored
File diff suppressed because one or more lines are too long
125
lib/main.js
125
lib/main.js
@@ -5,7 +5,7 @@ import pRetry from "p-retry";
|
|||||||
* @param {string} appId
|
* @param {string} appId
|
||||||
* @param {string} privateKey
|
* @param {string} privateKey
|
||||||
* @param {string} owner
|
* @param {string} owner
|
||||||
* @param {string} repositories
|
* @param {string[]} repositories
|
||||||
* @param {import("@actions/core")} core
|
* @param {import("@actions/core")} core
|
||||||
* @param {import("@octokit/auth-app").createAppAuth} createAppAuth
|
* @param {import("@octokit/auth-app").createAppAuth} createAppAuth
|
||||||
* @param {import("@octokit/request").request} request
|
* @param {import("@octokit/request").request} request
|
||||||
@@ -22,21 +22,21 @@ export async function main(
|
|||||||
skipTokenRevoke
|
skipTokenRevoke
|
||||||
) {
|
) {
|
||||||
let parsedOwner = "";
|
let parsedOwner = "";
|
||||||
let parsedRepositoryNames = "";
|
let parsedRepositoryNames = [];
|
||||||
|
|
||||||
// If neither owner nor repositories are set, default to current repository
|
// If neither owner nor repositories are set, default to current repository
|
||||||
if (!owner && !repositories) {
|
if (!owner && repositories.length === 0) {
|
||||||
[parsedOwner, parsedRepositoryNames] = String(
|
const [owner, repo] = String(process.env.GITHUB_REPOSITORY).split("/");
|
||||||
process.env.GITHUB_REPOSITORY
|
parsedOwner = owner;
|
||||||
).split("/");
|
parsedRepositoryNames = [repo];
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`owner and repositories not set, creating token for the current repository ("${parsedRepositoryNames}")`
|
`owner and repositories not set, creating token for the current repository ("${repo}")`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If only an owner is set, default to all repositories from that owner
|
// If only an owner is set, default to all repositories from that owner
|
||||||
if (owner && !repositories) {
|
if (owner && repositories.length === 0) {
|
||||||
parsedOwner = owner;
|
parsedOwner = owner;
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
@@ -45,22 +45,26 @@ export async function main(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If repositories are set, but no owner, default to `GITHUB_REPOSITORY_OWNER`
|
// If repositories are set, but no owner, default to `GITHUB_REPOSITORY_OWNER`
|
||||||
if (!owner && repositories) {
|
if (!owner && repositories.length > 0) {
|
||||||
parsedOwner = String(process.env.GITHUB_REPOSITORY_OWNER);
|
parsedOwner = String(process.env.GITHUB_REPOSITORY_OWNER);
|
||||||
parsedRepositoryNames = repositories;
|
parsedRepositoryNames = repositories;
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`owner not set, creating owner for given repositories "${repositories}" in current owner ("${parsedOwner}")`
|
`owner not set, creating owner for given repositories "${repositories.join(
|
||||||
|
","
|
||||||
|
)}" in current owner ("${parsedOwner}")`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If both owner and repositories are set, use those values
|
// If both owner and repositories are set, use those values
|
||||||
if (owner && repositories) {
|
if (owner && repositories.length > 0) {
|
||||||
parsedOwner = owner;
|
parsedOwner = owner;
|
||||||
parsedRepositoryNames = repositories;
|
parsedRepositoryNames = repositories;
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`owner and repositories set, creating token for repositories "${repositories}" owned by "${owner}"`
|
`owner and repositories set, creating token for repositories "${repositories.join(
|
||||||
|
","
|
||||||
|
)}" owned by "${owner}"`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,61 +74,66 @@ export async function main(
|
|||||||
request,
|
request,
|
||||||
});
|
});
|
||||||
|
|
||||||
let authentication;
|
let authentication, installationId, appSlug;
|
||||||
// If at least one repository is set, get installation ID from that repository
|
// If at least one repository is set, get installation ID from that repository
|
||||||
|
|
||||||
if (parsedRepositoryNames) {
|
if (parsedRepositoryNames.length > 0) {
|
||||||
authentication = await pRetry(() => getTokenFromRepository(request, auth, parsedOwner, parsedRepositoryNames), {
|
({ authentication, installationId, appSlug } = await pRetry(
|
||||||
onFailedAttempt: (error) => {
|
() =>
|
||||||
core.info(
|
getTokenFromRepository(
|
||||||
`Failed to create token for "${parsedRepositoryNames}" (attempt ${error.attemptNumber}): ${error.message}`
|
request,
|
||||||
);
|
auth,
|
||||||
},
|
parsedOwner,
|
||||||
retries: 3,
|
parsedRepositoryNames
|
||||||
});
|
),
|
||||||
|
{
|
||||||
|
onFailedAttempt: (error) => {
|
||||||
|
core.info(
|
||||||
|
`Failed to create token for "${parsedRepositoryNames.join(
|
||||||
|
","
|
||||||
|
)}" (attempt ${error.attemptNumber}): ${error.message}`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
retries: 3,
|
||||||
|
}
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
// Otherwise get the installation for the owner, which can either be an organization or a user account
|
// Otherwise get the installation for the owner, which can either be an organization or a user account
|
||||||
authentication = await pRetry(() => getTokenFromOwner(request, auth, parsedOwner), {
|
({ authentication, installationId, appSlug } = await pRetry(
|
||||||
onFailedAttempt: (error) => {
|
() => getTokenFromOwner(request, auth, parsedOwner),
|
||||||
core.info(
|
{
|
||||||
`Failed to create token for "${parsedOwner}" (attempt ${error.attemptNumber}): ${error.message}`
|
onFailedAttempt: (error) => {
|
||||||
);
|
core.info(
|
||||||
},
|
`Failed to create token for "${parsedOwner}" (attempt ${error.attemptNumber}): ${error.message}`
|
||||||
retries: 3,
|
);
|
||||||
});
|
},
|
||||||
|
retries: 3,
|
||||||
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the token with the runner as a secret to ensure it is masked in logs
|
// Register the token with the runner as a secret to ensure it is masked in logs
|
||||||
core.setSecret(authentication.token);
|
core.setSecret(authentication.token);
|
||||||
|
|
||||||
core.setOutput("token", authentication.token);
|
core.setOutput("token", authentication.token);
|
||||||
|
core.setOutput("installation-id", installationId);
|
||||||
|
core.setOutput("app-slug", appSlug);
|
||||||
|
|
||||||
// Make token accessible to post function (so we can invalidate it)
|
// Make token accessible to post function (so we can invalidate it)
|
||||||
if (!skipTokenRevoke) {
|
if (!skipTokenRevoke) {
|
||||||
core.saveState("token", authentication.token);
|
core.saveState("token", authentication.token);
|
||||||
core.setOutput("expiresAt", authentication.expiresAt);
|
core.saveState("expiresAt", authentication.expiresAt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTokenFromOwner(request, auth, parsedOwner) {
|
async function getTokenFromOwner(request, auth, parsedOwner) {
|
||||||
// https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-an-organization-installation-for-the-authenticated-app
|
// https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#get-a-user-installation-for-the-authenticated-app
|
||||||
const response = await request("GET /orgs/{org}/installation", {
|
// This endpoint works for both users and organizations
|
||||||
org: parsedOwner,
|
const response = await request("GET /users/{username}/installation", {
|
||||||
|
username: parsedOwner,
|
||||||
request: {
|
request: {
|
||||||
hook: auth.hook,
|
hook: auth.hook,
|
||||||
},
|
},
|
||||||
}).catch((error) => {
|
|
||||||
/* c8 ignore next */
|
|
||||||
if (error.status !== 404) throw error;
|
|
||||||
|
|
||||||
// https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#get-a-user-installation-for-the-authenticated-app
|
|
||||||
return request("GET /users/{username}/installation", {
|
|
||||||
username: parsedOwner,
|
|
||||||
request: {
|
|
||||||
hook: auth.hook,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get token for for all repositories of the given installation
|
// Get token for for all repositories of the given installation
|
||||||
@@ -132,14 +141,23 @@ async function getTokenFromOwner(request, auth, parsedOwner) {
|
|||||||
type: "installation",
|
type: "installation",
|
||||||
installationId: response.data.id,
|
installationId: response.data.id,
|
||||||
});
|
});
|
||||||
return authentication;
|
|
||||||
|
const installationId = response.data.id;
|
||||||
|
const appSlug = response.data["app_slug"];
|
||||||
|
|
||||||
|
return { authentication, installationId, appSlug };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTokenFromRepository(request, auth, parsedOwner, parsedRepositoryNames) {
|
async function getTokenFromRepository(
|
||||||
|
request,
|
||||||
|
auth,
|
||||||
|
parsedOwner,
|
||||||
|
parsedRepositoryNames
|
||||||
|
) {
|
||||||
// https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app
|
// https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app
|
||||||
const response = await request("GET /repos/{owner}/{repo}/installation", {
|
const response = await request("GET /repos/{owner}/{repo}/installation", {
|
||||||
owner: parsedOwner,
|
owner: parsedOwner,
|
||||||
repo: parsedRepositoryNames.split(",")[0],
|
repo: parsedRepositoryNames[0],
|
||||||
request: {
|
request: {
|
||||||
hook: auth.hook,
|
hook: auth.hook,
|
||||||
},
|
},
|
||||||
@@ -149,8 +167,11 @@ async function getTokenFromRepository(request, auth, parsedOwner, parsedReposito
|
|||||||
const authentication = await auth({
|
const authentication = await auth({
|
||||||
type: "installation",
|
type: "installation",
|
||||||
installationId: response.data.id,
|
installationId: response.data.id,
|
||||||
repositoryNames: parsedRepositoryNames.split(","),
|
repositoryNames: parsedRepositoryNames,
|
||||||
});
|
});
|
||||||
|
|
||||||
return authentication;
|
const installationId = response.data.id;
|
||||||
}
|
const appSlug = response.data["app_slug"];
|
||||||
|
|
||||||
|
return { authentication, installationId, appSlug };
|
||||||
|
}
|
||||||
|
|||||||
5
main.js
5
main.js
@@ -25,7 +25,10 @@ if (!privateKey) {
|
|||||||
throw new Error("Input required and not supplied: private-key");
|
throw new Error("Input required and not supplied: private-key");
|
||||||
}
|
}
|
||||||
const owner = core.getInput("owner");
|
const owner = core.getInput("owner");
|
||||||
const repositories = core.getInput("repositories");
|
const repositories = core.getInput("repositories")
|
||||||
|
.split(/[\n,]+/)
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(x => x !== '');
|
||||||
|
|
||||||
const skipTokenRevoke = Boolean(
|
const skipTokenRevoke = Boolean(
|
||||||
core.getInput("skip-token-revoke") || core.getInput("skip_token_revoke")
|
core.getInput("skip-token-revoke") || core.getInput("skip_token_revoke")
|
||||||
|
|||||||
2204
package-lock.json
generated
2204
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@@ -2,31 +2,31 @@
|
|||||||
"name": "create-github-app-token",
|
"name": "create-github-app-token",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "1.8.0",
|
"version": "1.11.1",
|
||||||
"description": "GitHub Action for creating a GitHub App Installation Access Token",
|
"description": "GitHub Action for creating a GitHub App Installation Access Token",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "esbuild main.js post.js --bundle --outdir=dist --out-extension:.js=.cjs --platform=node --target=node20.0.0",
|
"build": "esbuild main.js post.js --bundle --outdir=dist --out-extension:.js=.cjs --platform=node --target=node20.0.0 --packages=bundle",
|
||||||
"test": "c8 --100 ava tests/index.js",
|
"test": "c8 --100 ava tests/index.js",
|
||||||
"coverage": "c8 report --reporter html",
|
"coverage": "c8 report --reporter html",
|
||||||
"postcoverage": "open-cli coverage/index.html"
|
"postcoverage": "open-cli coverage/index.html"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@octokit/auth-app": "^6.0.3",
|
"@octokit/auth-app": "^7.1.3",
|
||||||
"@octokit/request": "^8.1.6",
|
"@octokit/request": "^9.1.3",
|
||||||
"p-retry": "^6.2.0",
|
"p-retry": "^6.2.1",
|
||||||
"undici": "^6.6.0"
|
"undici": "^6.19.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sinonjs/fake-timers": "^11.2.2",
|
"@sinonjs/fake-timers": "^13.0.2",
|
||||||
"ava": "^6.1.1",
|
"ava": "^6.2.0",
|
||||||
"c8": "^9.1.0",
|
"c8": "^10.1.3",
|
||||||
"dotenv": "^16.4.1",
|
"dotenv": "^16.4.7",
|
||||||
"esbuild": "^0.20.0",
|
"esbuild": "^0.24.0",
|
||||||
"execa": "^8.0.1",
|
"execa": "^9.5.2",
|
||||||
"open-cli": "^8.0.0",
|
"open-cli": "^8.0.0",
|
||||||
"yaml": "^2.3.4"
|
"yaml": "^2.6.1"
|
||||||
},
|
},
|
||||||
"release": {
|
"release": {
|
||||||
"branches": [
|
"branches": [
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
import { readdirSync } from "node:fs";
|
import { readdirSync } from "node:fs";
|
||||||
|
|
||||||
import { execa } from "execa";
|
|
||||||
import test from "ava";
|
import test from "ava";
|
||||||
|
import { execa } from "execa";
|
||||||
|
|
||||||
const tests = readdirSync("tests").filter((file) => file.endsWith(".test.js"));
|
// Get all files in tests directory
|
||||||
|
const files = readdirSync("tests");
|
||||||
|
|
||||||
for (const file of tests) {
|
// Files to ignore
|
||||||
|
const ignore = ["index.js", "main.js", "README.md", "snapshots"];
|
||||||
|
|
||||||
|
const testFiles = files.filter((file) => !ignore.includes(file));
|
||||||
|
|
||||||
|
// Throw an error if there is a file that does not end with test.js in the tests directory
|
||||||
|
for (const file of testFiles) {
|
||||||
|
if (!file.endsWith(".test.js")) {
|
||||||
|
throw new Error(`File ${file} does not end with .test.js`);
|
||||||
|
}
|
||||||
test(file, async (t) => {
|
test(file, async (t) => {
|
||||||
// Override Actions environment variables that change `core`’s behavior
|
// Override Actions environment variables that change `core`’s behavior
|
||||||
const env = {
|
const env = {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { test, DEFAULT_ENV } from "./main.js";
|
import { DEFAULT_ENV, test } from "./main.js";
|
||||||
|
|
||||||
// Verify that main works with a custom GitHub API URL passed as `github-api-url` input
|
// Verify that main works with a custom GitHub API URL passed as `github-api-url` input
|
||||||
await test(
|
await test(
|
||||||
() => {
|
() => {
|
||||||
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
||||||
process.env.INPUT_REPOSITORIES = process.env.GITHUB_REPOSITORY;
|
const currentRepoName = process.env.GITHUB_REPOSITORY.split("/")[1];
|
||||||
|
process.env.INPUT_REPOSITORIES = currentRepoName;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...DEFAULT_ENV,
|
...DEFAULT_ENV,
|
||||||
|
|||||||
9
tests/main-private-key-with-escaped-newlines.test.js
Normal file
9
tests/main-private-key-with-escaped-newlines.test.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { DEFAULT_ENV, test } from "./main.js";
|
||||||
|
|
||||||
|
// Verify `main` works correctly when `private-key` input has escaped newlines
|
||||||
|
await test(() => {
|
||||||
|
process.env["INPUT_PRIVATE-KEY"] = DEFAULT_ENV["INPUT_PRIVATE-KEY"].replace(
|
||||||
|
/\n/g,
|
||||||
|
"\\n"
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -9,6 +9,7 @@ await test((mockPool) => {
|
|||||||
const owner = process.env.INPUT_OWNER
|
const owner = process.env.INPUT_OWNER
|
||||||
const repo = process.env.INPUT_REPOSITORIES
|
const repo = process.env.INPUT_REPOSITORIES
|
||||||
const mockInstallationId = "123456";
|
const mockInstallationId = "123456";
|
||||||
|
const mockAppSlug = "github-actions";
|
||||||
|
|
||||||
install({ now: 0, toFake: ["Date"] });
|
install({ now: 0, toFake: ["Date"] });
|
||||||
|
|
||||||
@@ -44,7 +45,8 @@ await test((mockPool) => {
|
|||||||
return {
|
return {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
data: {
|
data: {
|
||||||
id: mockInstallationId
|
id: mockInstallationId,
|
||||||
|
"app_slug": mockAppSlug
|
||||||
},
|
},
|
||||||
responseOptions: {
|
responseOptions: {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
import { test } from "./main.js";
|
import { test } from "./main.js";
|
||||||
|
|
||||||
// Verify `main` successfully obtains a token when the `owner` input is set (to a user), but the `repositories` input isn’t set.
|
// Verify retries work when getting a token for a user or organization fails on the first attempt.
|
||||||
await test((mockPool) => {
|
await test((mockPool) => {
|
||||||
process.env.INPUT_OWNER = "smockle";
|
process.env.INPUT_OWNER = "smockle";
|
||||||
delete process.env.INPUT_REPOSITORIES;
|
delete process.env.INPUT_REPOSITORIES;
|
||||||
|
|
||||||
// Mock installation id request
|
// Mock installation ID and app slug request
|
||||||
const mockInstallationId = "123456";
|
const mockInstallationId = "123456";
|
||||||
|
const mockAppSlug = "github-actions";
|
||||||
mockPool
|
mockPool
|
||||||
.intercept({
|
.intercept({
|
||||||
path: `/orgs/${process.env.INPUT_OWNER}/installation`,
|
path: `/users/${process.env.INPUT_OWNER}/installation`,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/vnd.github.v3+json",
|
accept: "application/vnd.github.v3+json",
|
||||||
@@ -17,7 +18,7 @@ await test((mockPool) => {
|
|||||||
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
|
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.reply(404);
|
.reply(500, "GitHub API not available");
|
||||||
mockPool
|
mockPool
|
||||||
.intercept({
|
.intercept({
|
||||||
path: `/users/${process.env.INPUT_OWNER}/installation`,
|
path: `/users/${process.env.INPUT_OWNER}/installation`,
|
||||||
@@ -30,7 +31,7 @@ await test((mockPool) => {
|
|||||||
})
|
})
|
||||||
.reply(
|
.reply(
|
||||||
200,
|
200,
|
||||||
{ id: mockInstallationId },
|
{ id: mockInstallationId, app_slug: mockAppSlug },
|
||||||
{ headers: { "content-type": "application/json" } }
|
{ headers: { "content-type": "application/json" } }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -7,6 +7,7 @@ await test((mockPool) => {
|
|||||||
const owner = process.env.INPUT_OWNER;
|
const owner = process.env.INPUT_OWNER;
|
||||||
const repo = process.env.INPUT_REPOSITORIES;
|
const repo = process.env.INPUT_REPOSITORIES;
|
||||||
const mockInstallationId = "123456";
|
const mockInstallationId = "123456";
|
||||||
|
const mockAppSlug = "github-actions";
|
||||||
|
|
||||||
mockPool
|
mockPool
|
||||||
.intercept({
|
.intercept({
|
||||||
@@ -32,7 +33,7 @@ await test((mockPool) => {
|
|||||||
})
|
})
|
||||||
.reply(
|
.reply(
|
||||||
200,
|
200,
|
||||||
{ id: mockInstallationId },
|
{ id: mockInstallationId, "app_slug": mockAppSlug },
|
||||||
{ headers: { "content-type": "application/json" } }
|
{ headers: { "content-type": "application/json" } }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { test } from "./main.js";
|
||||||
|
|
||||||
|
// Verify `main` successfully obtains a token when the `owner` and `repositories` inputs are set (and the latter is a list of repos).
|
||||||
|
await test(() => {
|
||||||
|
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
||||||
|
const currentRepoName = process.env.GITHUB_REPOSITORY.split("/")[1];
|
||||||
|
// Intentional unnecessary whitespace to test parsing to array
|
||||||
|
process.env.INPUT_REPOSITORIES = `\n ${currentRepoName}\ntoolkit \n\n checkout \n`;
|
||||||
|
});
|
||||||
@@ -3,5 +3,7 @@ import { test } from "./main.js";
|
|||||||
// Verify `main` successfully obtains a token when the `owner` and `repositories` inputs are set (and the latter is a list of repos).
|
// Verify `main` successfully obtains a token when the `owner` and `repositories` inputs are set (and the latter is a list of repos).
|
||||||
await test(() => {
|
await test(() => {
|
||||||
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
||||||
process.env.INPUT_REPOSITORIES = `${process.env.GITHUB_REPOSITORY},actions/toolkit`;
|
const currentRepoName = process.env.GITHUB_REPOSITORY.split("/")[1];
|
||||||
|
// Intentional unnecessary whitespace to test parsing to array
|
||||||
|
process.env.INPUT_REPOSITORIES = ` ${currentRepoName}, toolkit ,checkout`;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ import { test } from "./main.js";
|
|||||||
// Verify `main` successfully obtains a token when the `owner` and `repositories` inputs are set (and the latter is a single repo).
|
// Verify `main` successfully obtains a token when the `owner` and `repositories` inputs are set (and the latter is a single repo).
|
||||||
await test(() => {
|
await test(() => {
|
||||||
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
||||||
process.env.INPUT_REPOSITORIES = process.env.GITHUB_REPOSITORY;
|
const currentRepoName = process.env.GITHUB_REPOSITORY.split("/")[1];
|
||||||
|
process.env.INPUT_REPOSITORIES = currentRepoName;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import { test } from "./main.js";
|
import { test } from "./main.js";
|
||||||
|
|
||||||
// Verify `main` successfully obtains a token when the `owner` input is set (to an org), but the `repositories` input isn’t set.
|
// Verify `main` successfully obtains a token when the `owner` input is set, and the `repositories` input isn’t set.
|
||||||
await test((mockPool) => {
|
await test((mockPool) => {
|
||||||
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
||||||
delete process.env.INPUT_REPOSITORIES;
|
delete process.env.INPUT_REPOSITORIES;
|
||||||
|
|
||||||
// Mock installation id request
|
// Mock installation ID and app slug request
|
||||||
const mockInstallationId = "123456";
|
const mockInstallationId = "123456";
|
||||||
|
const mockAppSlug = "github-actions";
|
||||||
mockPool
|
mockPool
|
||||||
.intercept({
|
.intercept({
|
||||||
path: `/orgs/${process.env.INPUT_OWNER}/installation`,
|
path: `/users/${process.env.INPUT_OWNER}/installation`,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/vnd.github.v3+json",
|
accept: "application/vnd.github.v3+json",
|
||||||
@@ -19,7 +20,7 @@ await test((mockPool) => {
|
|||||||
})
|
})
|
||||||
.reply(
|
.reply(
|
||||||
200,
|
200,
|
||||||
{ id: mockInstallationId },
|
{ id: mockInstallationId, app_slug: mockAppSlug },
|
||||||
{ headers: { "content-type": "application/json" } }
|
{ headers: { "content-type": "application/json" } }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import { test } from "./main.js";
|
|
||||||
|
|
||||||
// Verify `main` successfully obtains a token when the `owner` input is set (to a user), but the `repositories` input isn’t set.
|
|
||||||
await test((mockPool) => {
|
|
||||||
process.env.INPUT_OWNER = "smockle";
|
|
||||||
delete process.env.INPUT_REPOSITORIES;
|
|
||||||
|
|
||||||
// Mock installation id request
|
|
||||||
const mockInstallationId = "123456";
|
|
||||||
mockPool
|
|
||||||
.intercept({
|
|
||||||
path: `/orgs/${process.env.INPUT_OWNER}/installation`,
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
accept: "application/vnd.github.v3+json",
|
|
||||||
"user-agent": "actions/create-github-app-token",
|
|
||||||
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.reply(500, "GitHub API not available");
|
|
||||||
mockPool
|
|
||||||
.intercept({
|
|
||||||
path: `/orgs/${process.env.INPUT_OWNER}/installation`,
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
accept: "application/vnd.github.v3+json",
|
|
||||||
"user-agent": "actions/create-github-app-token",
|
|
||||||
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.reply(
|
|
||||||
200,
|
|
||||||
{ id: mockInstallationId },
|
|
||||||
{ headers: { "content-type": "application/json" } }
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -3,5 +3,6 @@ import { test } from "./main.js";
|
|||||||
// Verify `main` successfully obtains a token when the `owner` input is not set, but the `repositories` input is set.
|
// Verify `main` successfully obtains a token when the `owner` input is not set, but the `repositories` input is set.
|
||||||
await test(() => {
|
await test(() => {
|
||||||
delete process.env.INPUT_OWNER;
|
delete process.env.INPUT_OWNER;
|
||||||
process.env.INPUT_REPOSITORIES = process.env.GITHUB_REPOSITORY;
|
const currentRepoName = process.env.GITHUB_REPOSITORY.split("/")[1];
|
||||||
|
process.env.INPUT_REPOSITORIES = currentRepoName;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ await test((mockPool) => {
|
|||||||
delete process.env.INPUT_OWNER;
|
delete process.env.INPUT_OWNER;
|
||||||
delete process.env.INPUT_REPOSITORIES;
|
delete process.env.INPUT_REPOSITORIES;
|
||||||
|
|
||||||
// Mock installation id request
|
// Mock installation ID and app slug request
|
||||||
const mockInstallationId = "123456";
|
const mockInstallationId = "123456";
|
||||||
|
const mockAppSlug = "github-actions";
|
||||||
mockPool
|
mockPool
|
||||||
.intercept({
|
.intercept({
|
||||||
path: `/repos/${process.env.GITHUB_REPOSITORY}/installation`,
|
path: `/repos/${process.env.GITHUB_REPOSITORY}/installation`,
|
||||||
@@ -19,7 +20,7 @@ await test((mockPool) => {
|
|||||||
})
|
})
|
||||||
.reply(
|
.reply(
|
||||||
200,
|
200,
|
||||||
{ id: mockInstallationId },
|
{ id: mockInstallationId, "app_slug": mockAppSlug },
|
||||||
{ headers: { "content-type": "application/json" } }
|
{ headers: { "content-type": "application/json" } }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
|||||||
|
|
||||||
// Set up mocking
|
// Set up mocking
|
||||||
const baseUrl = new URL(env["INPUT_GITHUB-API-URL"]);
|
const baseUrl = new URL(env["INPUT_GITHUB-API-URL"]);
|
||||||
const basePath = baseUrl.pathname === '/' ? '' : baseUrl.pathname;
|
const basePath = baseUrl.pathname === "/" ? "" : baseUrl.pathname;
|
||||||
const mockAgent = new MockAgent();
|
const mockAgent = new MockAgent();
|
||||||
mockAgent.disableNetConnect();
|
mockAgent.disableNetConnect();
|
||||||
setGlobalDispatcher(mockAgent);
|
setGlobalDispatcher(mockAgent);
|
||||||
@@ -54,11 +54,13 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
|||||||
|
|
||||||
// Calling `auth({ type: "app" })` to obtain a JWT doesn’t make network requests, so no need to intercept.
|
// Calling `auth({ type: "app" })` to obtain a JWT doesn’t make network requests, so no need to intercept.
|
||||||
|
|
||||||
// Mock installation id request
|
// Mock installation ID and app slug request
|
||||||
const mockInstallationId = "123456";
|
const mockInstallationId = "123456";
|
||||||
|
const mockAppSlug = "github-actions";
|
||||||
const owner = env.INPUT_OWNER ?? env.GITHUB_REPOSITORY_OWNER;
|
const owner = env.INPUT_OWNER ?? env.GITHUB_REPOSITORY_OWNER;
|
||||||
|
const currentRepoName = env.GITHUB_REPOSITORY.split("/")[1];
|
||||||
const repo = encodeURIComponent(
|
const repo = encodeURIComponent(
|
||||||
(env.INPUT_REPOSITORIES ?? env.GITHUB_REPOSITORY).split(",")[0]
|
(env.INPUT_REPOSITORIES ?? currentRepoName).split(",")[0]
|
||||||
);
|
);
|
||||||
mockPool
|
mockPool
|
||||||
.intercept({
|
.intercept({
|
||||||
@@ -72,7 +74,7 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
|||||||
})
|
})
|
||||||
.reply(
|
.reply(
|
||||||
200,
|
200,
|
||||||
{ id: mockInstallationId },
|
{ id: mockInstallationId, app_slug: mockAppSlug },
|
||||||
{ headers: { "content-type": "application/json" } }
|
{ headers: { "content-type": "application/json" } }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -24,13 +24,16 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
|
|
||||||
> stdout
|
> stdout
|
||||||
|
|
||||||
`owner and repositories set, creating token for repositories "actions/create-github-app-token" owned by "actions"␊
|
`owner and repositories set, creating token for repositories "create-github-app-token" owned by "actions"␊
|
||||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
␊
|
␊
|
||||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
␊
|
||||||
::set-output name=expiresAt::2016-07-11T22:14:10Z`
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
## main-missing-app-id.test.js
|
## main-missing-app-id.test.js
|
||||||
|
|
||||||
@@ -72,6 +75,65 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
|
|
||||||
''
|
''
|
||||||
|
|
||||||
|
## main-private-key-with-escaped-newlines.test.js
|
||||||
|
|
||||||
|
> stderr
|
||||||
|
|
||||||
|
''
|
||||||
|
|
||||||
|
> stdout
|
||||||
|
|
||||||
|
`owner and repositories not set, creating token for the current repository ("create-github-app-token")␊
|
||||||
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
␊
|
||||||
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
␊
|
||||||
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
|
## main-repo-skew.test.js
|
||||||
|
|
||||||
|
> stderr
|
||||||
|
|
||||||
|
`'Issued at' claim ('iat') must be an Integer representing the time that the assertion was issued.␊
|
||||||
|
[@octokit/auth-app] GitHub API time and system time are different by 30 seconds. Retrying request with the difference accounted for.`
|
||||||
|
|
||||||
|
> stdout
|
||||||
|
|
||||||
|
`owner and repositories set, creating token for repositories "failed-repo" owned by "actions"␊
|
||||||
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
␊
|
||||||
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
␊
|
||||||
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
|
## main-token-get-owner-set-fail-response.test.js
|
||||||
|
|
||||||
|
> stderr
|
||||||
|
|
||||||
|
''
|
||||||
|
|
||||||
|
> stdout
|
||||||
|
|
||||||
|
`repositories not set, creating token for all repositories for given owner "smockle"␊
|
||||||
|
Failed to create token for "smockle" (attempt 1): GitHub API not available␊
|
||||||
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
␊
|
||||||
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
␊
|
||||||
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
## main-token-get-owner-set-repo-fail-response.test.js
|
## main-token-get-owner-set-repo-fail-response.test.js
|
||||||
|
|
||||||
> stderr
|
> stderr
|
||||||
@@ -85,9 +147,31 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
␊
|
␊
|
||||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
␊
|
||||||
::set-output name=expiresAt::2016-07-11T22:14:10Z`
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
|
## main-token-get-owner-set-repo-set-to-many-newline.test.js
|
||||||
|
|
||||||
|
> stderr
|
||||||
|
|
||||||
|
''
|
||||||
|
|
||||||
|
> stdout
|
||||||
|
|
||||||
|
`owner and repositories set, creating token for repositories "create-github-app-token,toolkit,checkout" owned by "actions"␊
|
||||||
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
␊
|
||||||
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
␊
|
||||||
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
## main-token-get-owner-set-repo-set-to-many.test.js
|
## main-token-get-owner-set-repo-set-to-many.test.js
|
||||||
|
|
||||||
@@ -97,13 +181,16 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
|
|
||||||
> stdout
|
> stdout
|
||||||
|
|
||||||
`owner and repositories set, creating token for repositories "actions/create-github-app-token,actions/toolkit" owned by "actions"␊
|
`owner and repositories set, creating token for repositories "create-github-app-token,toolkit,checkout" owned by "actions"␊
|
||||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
␊
|
␊
|
||||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
␊
|
||||||
::set-output name=expiresAt::2016-07-11T22:14:10Z`
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
## main-token-get-owner-set-repo-set-to-one.test.js
|
## main-token-get-owner-set-repo-set-to-one.test.js
|
||||||
|
|
||||||
@@ -113,15 +200,18 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
|
|
||||||
> stdout
|
> stdout
|
||||||
|
|
||||||
`owner and repositories set, creating token for repositories "actions/create-github-app-token" owned by "actions"␊
|
`owner and repositories set, creating token for repositories "create-github-app-token" owned by "actions"␊
|
||||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
␊
|
␊
|
||||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
␊
|
||||||
::set-output name=expiresAt::2016-07-11T22:14:10Z`
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
## main-token-get-owner-set-to-org-repo-unset.test.js
|
## main-token-get-owner-set-repo-unset.test.js
|
||||||
|
|
||||||
> stderr
|
> stderr
|
||||||
|
|
||||||
@@ -133,42 +223,12 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
␊
|
␊
|
||||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
␊
|
||||||
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
␊
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
::set-output name=expiresAt::2016-07-11T22:14:10Z`
|
|
||||||
|
|
||||||
## main-token-get-owner-set-to-user-fail-response.test.js
|
|
||||||
|
|
||||||
> stderr
|
|
||||||
|
|
||||||
''
|
|
||||||
|
|
||||||
> stdout
|
|
||||||
|
|
||||||
`repositories not set, creating token for all repositories for given owner "smockle"␊
|
|
||||||
Failed to create token for "smockle" (attempt 1): GitHub API not available␊
|
|
||||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
|
||||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
|
||||||
::set-output name=expiresAt::2016-07-11T22:14:10Z`
|
|
||||||
|
|
||||||
## main-token-get-owner-set-to-user-repo-unset.test.js
|
|
||||||
|
|
||||||
> stderr
|
|
||||||
|
|
||||||
''
|
|
||||||
|
|
||||||
> stdout
|
|
||||||
|
|
||||||
`repositories not set, creating token for all repositories for given owner "smockle"␊
|
|
||||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
|
||||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
|
||||||
::set-output name=expiresAt::2016-07-11T22:14:10Z`
|
|
||||||
|
|
||||||
## main-token-get-owner-unset-repo-set.test.js
|
## main-token-get-owner-unset-repo-set.test.js
|
||||||
|
|
||||||
@@ -178,13 +238,16 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
|
|
||||||
> stdout
|
> stdout
|
||||||
|
|
||||||
`owner not set, creating owner for given repositories "actions/create-github-app-token" in current owner ("actions")␊
|
`owner not set, creating owner for given repositories "create-github-app-token" in current owner ("actions")␊
|
||||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
␊
|
␊
|
||||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
␊
|
||||||
::set-output name=expiresAt::2016-07-11T22:14:10Z`
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
## main-token-get-owner-unset-repo-unset.test.js
|
## main-token-get-owner-unset-repo-unset.test.js
|
||||||
|
|
||||||
@@ -198,9 +261,12 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
␊
|
␊
|
||||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
|
||||||
␊
|
␊
|
||||||
::set-output name=expiresAt::2016-07-11T22:14:10Z`
|
::set-output name=installation-id::123456␊
|
||||||
|
␊
|
||||||
|
::set-output name=app-slug::github-actions␊
|
||||||
|
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
|
||||||
|
::save-state name=expiresAt::2016-07-11T22:14:10Z`
|
||||||
|
|
||||||
## post-revoke-token-fail-response.test.js
|
## post-revoke-token-fail-response.test.js
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user