Skip to content

Commit

Permalink
chore: try alt auth method
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslice committed Jan 19, 2024
1 parent 05d4918 commit 921f629
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ jobs:
wasi: true
input: ''
output_type: text
github_token: ${{ github.token }}
token: ${{ github.token }}
steps: |-
test open issue | https://cdn.modsurfer.dylibso.com/api/v1/module/2ab8f671a0334e7da92c9cd8e0cca0dd710930e6019319126b6bed06aad342e9.wasm | test_open_issue
5 changes: 2 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ inputs:
description: 'A line-delimited, "|"-segmented list of Extism plug-ins to run in a pipeline. Components are: name | source (url or path) | function (optional export to call, default = run)'
required: true
default: ''
github_token:
description: 'The access token to use with authorized GitHub API calls.'
token:
description: 'The access token to use with authenticated GitHub API calls.'
required: false
default: ''
outputs:
output:
description: 'Final output of the last plugin run in this pipeline.'
Expand Down
22 changes: 14 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const { createActionAuth } = require("@octokit/auth-action");
const createPlugin = require("@extism/extism");

async function actism(input, steps, wasi, outputType, test) {
Expand All @@ -18,8 +19,6 @@ async function actism(input, steps, wasi, outputType, test) {
}
steps = steps.trim();
outputType = outputType.trim();

const githubToken = core.getInput('github_token').trim();

// for each step, run the step() function in the module with the input from the previous step
let pipelineData = input;
Expand All @@ -34,7 +33,7 @@ async function actism(input, steps, wasi, outputType, test) {
core.info("Starting step: \u001b[1;95m\033[4m" + step.name + "\033[24m\033[0m (" + step.source + ")")
const plugin = await createPlugin(step.source, {
useWasi: wasi,
functions: { "extism:host/user": ActionsBindings(githubToken) }
functions: { "extism:host/user": await ActionsBindings() }
});
const output = await plugin.call(step.entrypoint, pipelineData);
pipelineData = output.bytes();
Expand Down Expand Up @@ -78,21 +77,28 @@ const Steps = (input) => {
})
}

const ActionsBindings = (githubToken) => {
const ActionsBindings = async () => {
let octokit;
try {
const auth = createActionAuth();
const authentication = await auth();
octokit = github.getOctokit({ auth: auth.token });
} catch (e) {
core.debug(e);
octokit = undefined;
}
const hostFuncs = {};

hostFuncs.github_context = (plugin) => {
return plugin.store(JSON.stringify(github.context));
};

hostFuncs.github_open_issue = (plugin, titleOffs, bodyOffs) => {
if (githubToken.length === 0) {
core.setFailed(`Actism error: cannot call "gitub_open_issue" without token.`);
if (!octokit) {
core.setFailed(`Actism error: cannot call "gitub_open_issue" without providing 'token' in action params.`);
return;
}

console.log(`github_open_issue called, tmp token: ${btoa(githubToken)} size: ${githubToken.length}`);

const octokit = github.getOctokit({ auth: githubToken });
const title = plugin.read(titleOffs).text();
const body = plugin.read(bodyOffs).text();
Expand Down
16 changes: 14 additions & 2 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/@octokit/auth-action/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

179 changes: 179 additions & 0 deletions node_modules/@octokit/auth-action/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions node_modules/@octokit/auth-action/dist-node/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/@octokit/auth-action/dist-node/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 921f629

Please sign in to comment.