Skip to content

Add action typing #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/check-action-typing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Check Action Typing

on:
- push
- pull_request

jobs:
check_action_typing:
name: Check Action Typing
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check Action Typing
uses: typesafegithub/github-actions-typing@v2
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

GitHub Action for creating a GitHub App installation access token.

Thanks to the provided [typings](action-types.yml), it is possible to use this action in a type-safe way using
https://github.com/typesafegithub/github-workflows-kt which allows writing workflow files using a type-safe Kotlin DSL.

## Usage

In order to use this action, you need to:
Expand Down
321 changes: 321 additions & 0 deletions action-types.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit concerned about the long-term maintenance of these types and requiring this action's maintainers to keep them up to date.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, for the permissions I added the same update generation logic that is used for the action.yml.

For the others, yes, you would have to maintain them.
Which imho is a good thing, as it makes clear to users which types the inputs have and which values are valid in a defined technical way,
and any automatic consumer like DSL-generators can leverage the information and it is always up-to-date with the state of your action.

Unless you constantly add and remove inputs or outputs (other than the permissions which are generated), there should not be much additional effort hopefully, and the added action makes sure you don't forget to update them and have a valid format.

And even if you very often change inputs / outputs, it is just adding it to that file too to define the type, so hopefully even then not a significant additional effort. :-)

Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
# See https://github.com/typesafegithub/github-actions-typing
inputs:
app-id:
type: string

private-key:
type: string

owner:
type: string

repositories:
type: list
separator: "\n"
list-item:
type: string

skip-token-revoke:
type: boolean

github-api-url:
type: string

# <START GENERATED PERMISSIONS TYPES>
permission-actions:
type: enum
allowed-values:
- "read"
- "write"

permission-administration:
type: enum
allowed-values:
- "read"
- "write"

permission-checks:
type: enum
allowed-values:
- "read"
- "write"

permission-codespaces:
type: enum
allowed-values:
- "read"
- "write"

permission-contents:
type: enum
allowed-values:
- "read"
- "write"

permission-dependabot-secrets:
type: enum
allowed-values:
- "read"
- "write"

permission-deployments:
type: enum
allowed-values:
- "read"
- "write"

permission-email-addresses:
type: enum
allowed-values:
- "read"
- "write"

permission-environments:
type: enum
allowed-values:
- "read"
- "write"

permission-followers:
type: enum
allowed-values:
- "read"
- "write"

permission-git-ssh-keys:
type: enum
allowed-values:
- "read"
- "write"

permission-gpg-keys:
type: enum
allowed-values:
- "read"
- "write"

permission-interaction-limits:
type: enum
allowed-values:
- "read"
- "write"

permission-issues:
type: enum
allowed-values:
- "read"
- "write"

permission-members:
type: enum
allowed-values:
- "read"
- "write"

permission-metadata:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-administration:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-announcement-banners:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-copilot-seat-management:
type: enum
allowed-values:
- "write"

permission-organization-custom-org-roles:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-custom-properties:
type: enum
allowed-values:
- "read"
- "write"
- "admin"

permission-organization-custom-roles:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-events:
type: enum
allowed-values:
- "read"

permission-organization-hooks:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-packages:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-personal-access-token-requests:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-personal-access-tokens:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-plan:
type: enum
allowed-values:
- "read"

permission-organization-projects:
type: enum
allowed-values:
- "read"
- "write"
- "admin"

permission-organization-secrets:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-self-hosted-runners:
type: enum
allowed-values:
- "read"
- "write"

permission-organization-user-blocking:
type: enum
allowed-values:
- "read"
- "write"

permission-packages:
type: enum
allowed-values:
- "read"
- "write"

permission-pages:
type: enum
allowed-values:
- "read"
- "write"

permission-profile:
type: enum
allowed-values:
- "write"

permission-pull-requests:
type: enum
allowed-values:
- "read"
- "write"

permission-repository-custom-properties:
type: enum
allowed-values:
- "read"
- "write"

permission-repository-hooks:
type: enum
allowed-values:
- "read"
- "write"

permission-repository-projects:
type: enum
allowed-values:
- "read"
- "write"
- "admin"

permission-secret-scanning-alerts:
type: enum
allowed-values:
- "read"
- "write"

permission-secrets:
type: enum
allowed-values:
- "read"
- "write"

permission-security-events:
type: enum
allowed-values:
- "read"
- "write"

permission-single-file:
type: enum
allowed-values:
- "read"
- "write"

permission-starring:
type: enum
allowed-values:
- "read"
- "write"

permission-statuses:
type: enum
allowed-values:
- "read"
- "write"

permission-team-discussions:
type: enum
allowed-values:
- "read"
- "write"

permission-vulnerability-alerts:
type: enum
allowed-values:
- "read"
- "write"

permission-workflows:
type: enum
allowed-values:
- "write"

# <END GENERATED PERMISSIONS TYPES>

outputs:
token:
type: string

installation-id:
type: integer

app-slug:
type: string
29 changes: 26 additions & 3 deletions scripts/update-permission-inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,36 @@ const permissionsInputs = Object.entries(appPermissionsSchema.properties)
description: "${description}"`;
}, "");

const actionsYamlContent = await readFile("action.yml", "utf8");
const actionYamlContent = await readFile("action.yml", "utf8");

// In the action.yml file, replace the content between the `<START GENERATED PERMISSIONS INPUTS>` and `<END GENERATED PERMISSIONS INPUTS>` comments with the new content
const updatedActionsYamlContent = actionsYamlContent.replace(
const updatedActionYamlContent = actionYamlContent.replace(
/(?<=# <START GENERATED PERMISSIONS INPUTS>)(.|\n)*(?=# <END GENERATED PERMISSIONS INPUTS>)/,
Copy link
Preview

Copilot AI May 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting the complex regex pattern used in the replace method into a well-named constant or helper function to improve readability and maintainability.

Suggested change
/(?<=# <START GENERATED PERMISSIONS INPUTS>)(.|\n)*(?=# <END GENERATED PERMISSIONS INPUTS>)/,
PERMISSIONS_INPUTS_REGEX,

Copilot uses AI. Check for mistakes.

permissionsInputs + "\n "
);

await writeFile("action.yml", updatedActionsYamlContent, "utf8");
await writeFile("action.yml", updatedActionYamlContent, "utf8");
console.log("Updated action.yml with new permissions inputs");

const permissionsTypes = Object.entries(appPermissionsSchema.properties)
.sort((a, b) => a[0].localeCompare(b[0]))
.reduce((result, [key, value]) => {
const permissionAccessValues = value.enum.map((p) => ` - "${p}"`).reduce((result, p) => `${result}\n${p}`);
return `${result}
permission-${key.replace(/_/g, "-")}:
type: enum
allowed-values:
${permissionAccessValues}
`;
}, "");

const actionTypesYamlContent = await readFile("action-types.yml", "utf8");

// In the action-types.yml file, replace the content between the `<START GENERATED PERMISSIONS TYPES>` and `<END GENERATED PERMISSIONS TYPES>` comments with the new content
const updatedActionTypesYamlContent = actionTypesYamlContent.replace(
/(?<=# <START GENERATED PERMISSIONS TYPES>)(.|\n)*(?=# <END GENERATED PERMISSIONS TYPES>)/,
permissionsTypes + "\n "
);

await writeFile("action-types.yml", updatedActionTypesYamlContent, "utf8");
console.log("Updated action-types.yml with new permissions types");