Skip to content

Commit

Permalink
try app-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Rugvip committed Jun 29, 2022
1 parent 53d3735 commit aca385d
Show file tree
Hide file tree
Showing 34 changed files with 597 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ jobs:

steps:
- uses: backstage/actions/[email protected]
with:
app-id: ${{ secrets.BACKSTAGE_GOALIE_APPLICATION_ID }}
private-key: ${{ secrets.BACKSTAGE_GOALIE_PRIVATE_KEY }}
282 changes: 282 additions & 0 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .yarn/install-state.gz
Binary file not shown.
18 changes: 14 additions & 4 deletions cron/action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
name: Backstage Cron
description: Repository operations on a schedule
inputs:
github-token:
description: The GitHub token used to create an authenticated client
default: ${{ github.token }}
required: false
# github-token:
# description: The GitHub token used to create an authenticated client
# default: ${{ github.token }}
# required: false
app-id:
description: The Application ID of the GitHub App to use for authentication
required: true
private-key:
description: The Private Key of the GitHub App to use for authentication
required: true
# organization:
# description: The GitHub token used to create an authenticated client
# default: ${{ github.token }}
# required: true
outputs: {}
runs:
using: node16
Expand Down
11 changes: 9 additions & 2 deletions cron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import * as github from '@actions/github';
import { verifyDCO } from './verifyDCO';
import { mergeRenovatePRs } from './mergeRenovatePRs';
import { mkLog } from '../lib/mkLog';
import {
getApplicationToken,
readGetApplicationTokenOptions,
} from '../lib/getApplicationToken';

async function main() {
core.info(`Running cron!`);
const token = core.getInput('github-token', { required: true });
const client = github.getOctokit(token);

const client = getApplicationToken(readGetApplicationTokenOptions());

// const token = core.getInput('github-token', { required: true });
// const client = github.getOctokit(token);
const repoInfo = github.context.repo;

await Promise.all([
Expand Down
30 changes: 30 additions & 0 deletions lib/getApplicationToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import { createAppAuth } from '@octokit/auth-app';

interface Options {
appId: string;
privateKey: string;
// organization: string;
}

export function readGetApplicationTokenOptions(): Options {
return {
appId: core.getInput('app-id', { required: true }),
privateKey: core.getInput('private-key', { required: true }),
// organization: core.getInput('organization', { required: true }),
};
}

export function getApplicationToken(options: Options) {
const { appId, privateKey } = options;

const client = github.getOctokit('', {
authStrategy: createAppAuth,
auth: {
appId,
privateKey,
},
});
return client;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@actions/core": "^1.9.0",
"@actions/github": "^5.0.3",
"@octokit/auth-app": "^3.6.1",
"ts-node": "^10.8.1",
"typescript": "^4.7.4"
},
Expand Down
Loading

0 comments on commit aca385d

Please sign in to comment.