@octotask/adapter-github-actions
v1.0.1
Published
Adapter to run a Octotask application function in GitHub Actions
Downloads
77
Maintainers
Readme
:electric_plug: @octotask/adapter-github-actions
Adapter to run a Octotask application function in GitHub Actions
Usage
Create your Octotask Application as always
// app.js
export default (app) => {
app.on("issues.opened", async (context) => {
const params = context.issue({ body: "Hello World!" });
await context.octokit.issues.createComment(params);
});
};
Then in the entrypoint of your GitHub Action, require @octotask/adapter-github-actions
instead of octotask
// index.js
import { run } from "@octotask/adapter-github-actions";
import app from "./app.js";
run(app).catch((error) => {
console.error(error);
process.exit(1);
});
Then use index.js
as your entrypoint in the action.yml
file
name: "Octotask app name"
description: "Octotask app description."
runs:
using: "node20"
main: "index.js"
Important: Your external dependencies will not be installed, you have to either vendor them in by committing the contents of the node_modules
folder, or compile the code to a single executable script (recommended). See GitHub's documentation
For an example Octotask App that is continuously published as GitHub Action, see https://github.com/octotask/example-github-action#readme
How it works
Octotask is a framework for building GitHub Apps, which is different to creating GitHub Actions in many ways, but the functionality is the same:
Both get notified about events on GitHub, which you can act on. While a GitHub App gets notified about a GitHub event via a webhook request sent by GitHub, a GitHub Action can receive the event payload by reading a JSON file from the file system. We can abstract away the differences, so the same hello world example app shown above works in both environments.
Relevant differences for Octotask applications:
- You cannot authenticate as the app. The
octotask
instance you receive is authenticated using a GitHub token. In most cases the token will be set tosecrets.GITHUB_TOKEN
, which is an installation access token. The providedGITHUB_TOKEN
expires when the job is done or after 6 hours, whichever comes first. You do not have access to anAPP_ID
orPRIVATE_KEY
, you cannot create new tokens or renew the provided one. secrets.GITHUB_TOKEN
is scoped to the current repository. You cannot read data from other repositories unless they are public, you cannot update any other repositories, or access organization-level APIs.- You could provide a personal access token instead of
secrets.GITHUB_TOKEN
to workaround the limits of a repository-scoped token, but be sure you know what you are doing. - You don't need to configure
WEBHOOK_SECRET
, because no webhook request gets sent, the event information can directly be retrieved from environment variables and the local file system.
For a more thorough comparison, see @jasonetco's posts: