Skip to content

Commit fef8853

Browse files
release-v1.2.0
Release v1.2.0
2 parents 4c79f7a + 07cb88f commit fef8853

File tree

3 files changed

+101
-13
lines changed

3 files changed

+101
-13
lines changed

README.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# project-beta-automations
22

3+
[![latest release](https://img.shields.io/github/v/release/leonsteinhaeuser/project-beta-automations)](https://img.shields.io/github/v/release/leonsteinhaeuser/project-beta-automations)
4+
[![release date](https://img.shields.io/github/release-date/leonsteinhaeuser/project-beta-automations)](https://img.shields.io/github/release-date/leonsteinhaeuser/project-beta-automations)
5+
[![commits since release](https://img.shields.io/github/commits-since/leonsteinhaeuser/project-beta-automations/latest)](https://img.shields.io/github/commits-since/leonsteinhaeuser/project-beta-automations/latest)
6+
[![open: bugs](https://img.shields.io/github/issues/leonsteinhaeuser/project-beta-automations/bug)](https://img.shields.io/github/issues/leonsteinhaeuser/project-beta-automations/bug)
7+
[![open: feature requests](https://img.shields.io/github/issues/leonsteinhaeuser/project-beta-automations/feature%20request)](https://img.shields.io/github/issues/leonsteinhaeuser/project-beta-automations/feature%20request)
8+
[![issues closed](https://img.shields.io/github/issues-closed/leonsteinhaeuser/project-beta-automations)](https://img.shields.io/github/issues-closed/leonsteinhaeuser/project-beta-automations)
9+
[![license](https://img.shields.io/github/license/leonsteinhaeuser/project-beta-automations)](https://img.shields.io/github/license/leonsteinhaeuser/project-beta-automations)
10+
311
This repository provides the ability to automate GitHub issues and pull requests for [Github Projects (Beta)](https://docs.github.com/en/issues/trying-out-the-new-projects-experience/about-projects). To do this, it automates the **Status** and user-defined fields to put issues and pull requests into the desired status, and therefore the desired column in the Board view. If the issue or pull request does not already exist in the project, it will be added.
412

513
Note: GITHUB_TOKEN does not have the necessary scopes to access projects (beta).
@@ -14,16 +22,19 @@ Since the issues and pull requests from this repository are also managed by this
1422

1523
## Variables
1624

17-
| Variable | Required | Description |
18-
| ------------------ | -------- |----------- |
19-
| `gh_token` | true | The GitHub token to use for the automation. |
20-
| `user` | false | The GitHub username that owns the projectboard. Either a user or an organization must be specified. |
21-
| `organization` | false | The GitHub organization that owns the projectboard. Either a user or an organization must be specified. |
22-
| `project_id` | true | The projectboard id. |
23-
| `resource_node_id` | true | The id of the resource node. |
24-
| `status_value` | false | The status value to set. Must be one of the values defined in your project board **Status field settings**. If left unspecified, new items are added without an explicit status, and existing items are left alone. |
25-
| `operation_mode` | false | The operation mode to use. Must be one of `custom_field`, `status`. Defaults to: `status` |
26-
| `custom_field_values` | false | Provides the possibility to change custom fields. To be applied the **operation_mode** must be set to `custom_field`. For the json definition refer to [JSON-Definition](#JSON-Definition) |
25+
| Variable | Required | Description |
26+
| ------------------------ | -------- |------------ |
27+
| `gh_token` | false | The GitHub token to use for the automation. For App instructions refer to [GH App Auth](#GH-App-Auth). (`gh_token` or `gh_app_*` must be defined) |
28+
| `gh_app_ID` | false | The GitHub App ID used for App authentication. For App instructions refer to [GH App Auth](#GH-App-Auth). (`gh_token` or `gh_app_*` must be defined) |
29+
| `gh_app_installation_ID` | false | The Github App installation ID binding the App to the target org. For App instructions refer to [GH App Auth](#GH-App-Auth). (`gh_token` or `gh_app_*` must be defined) |
30+
| `gh_app_secret_key` | false | The Github App Secret key used to sign App JWT tokens. For App instructions refer to [GH App Auth](#GH-App-Auth). (`gh_token` or `gh_app_*` must be defined) |
31+
| `user` | false | The GitHub username that owns the projectboard. Either a user or an organization must be specified. |
32+
| `organization` | false | The GitHub organization that owns the projectboard. Either a user or an organization must be specified. |
33+
| `project_id` | true | The projectboard id. |
34+
| `resource_node_id` | true | The id of the resource node. |
35+
| `status_value` | false | The status value to set. Must be one of the values defined in your project board **Status field settings**. If left unspecified, new items are added without an explicit status, and existing items are left alone. |
36+
| `operation_mode` | false | The operation mode to use. Must be one of `custom_field`, `status`. Defaults to: `status` |
37+
| `custom_field_values` | false | Provides the possibility to change custom fields. To be applied the **operation_mode** must be set to `custom_field`. For the json definition refer to [JSON-Definition](#JSON-Definition) |
2738

2839
## Getting started
2940

@@ -123,6 +134,29 @@ jobs:
123134
status_value: ${{ env.done }} # Target status
124135
```
125136
137+
## GH App Auth
138+
139+
To leverage the App authentication with this action the following steps are needed:
140+
141+
- Create a GitHub App under your user or organisation as described in the [GitHub documentation](https://docs.github.com/en/developers/apps/building-github-apps/creating-a-github-app), note the App ID
142+
- Set the needed GitHub App permissions in order for the newly create App to access and manage Org Project, as described in the [GitHub documentation](https://docs.github.com/en/developers/apps/managing-github-apps/editing-a-github-apps-permissions). The minimum required permissions are:
143+
- Repo: Actions: RW
144+
- Repo: Checks: RO
145+
- Repo: Contents: RO
146+
- Repo: Environments: RO
147+
- Repo: Metadata: RO
148+
- Repo: PR: RW
149+
- Repo: Commit statuses: RO
150+
- Org: Members: RO
151+
- Org: Projects: RW
152+
- Create a private key to authenticate the newly created GitHub App as described in the [GitHub documentation](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps), treat the downloaded key as sensitive material, store it in a GitHub secret accessible by this action.
153+
- Install the app in the target organisation, note the installation ID
154+
- Configure this action with
155+
- `gh_app_secret_key` containing the aforementioned private key
156+
- `gh_app_ID` containing the app ID, auto-generated by GitHub in the first step
157+
- `gh_app_installation_ID` containing the installation ID, auto-generated by GitHub in the previous step. Binging the App to the Org
158+
159+
126160
## JSON-Definition
127161

128162
A single json object is defined as follows:

action.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@ name: "project beta automations"
22
description: 'GitHub beta projects status field automation for Issues and Pull Requests'
33
inputs:
44
gh_token:
5-
description: 'Permission token that grants permission to the GitHub API.'
6-
required: true
5+
description: 'Permission token that grants permission to the GitHub API. (Toke or App config is required)'
6+
required: false
7+
default: ""
8+
gh_app_secret_key:
9+
description: 'Github App secret RSA key used to sign App JWT tokens'
10+
required: false
11+
default: ""
12+
gh_app_ID:
13+
description: 'Github App ID used to authenticate againts the API'
14+
required: false
15+
default: ""
16+
gh_app_installation_ID:
17+
description: 'Github App installation ID used to retrive installation token'
18+
required: false
719
default: ""
820
organization:
921
description: 'Organization the project is stored in'
@@ -46,7 +58,18 @@ branding:
4658
runs:
4759
using: "composite"
4860
steps:
49-
- name: "Authenticate gh cli"
61+
- name: "Error missing auth conf"
62+
if: inputs.gh_app_secret_key == '' && inputs.gh_app_ID == '' && inputs.gh_token == ''
63+
shell: bash
64+
run: echo "No GH Auth method configured, provide PAT or App ID/Key"; exit 1
65+
66+
- name: "Authenticate gh cli Github App"
67+
if: inputs.gh_app_secret_key != '' && inputs.gh_app_ID != '' && inputs.gh_app_installation_ID
68+
shell: bash
69+
run: "${{ github.action_path }}/gh_app_credential_helper.sh \"${{ inputs.gh_app_secret_key }}\" \"${{ inputs.gh_app_ID }}\" \"${{ inputs.gh_app_installation_ID }}\" | gh auth login --with-token"
70+
71+
- name: "Authenticate gh cli PAT"
72+
if: inputs.gh_token != ''
5073
shell: bash
5174
run: echo "${{ inputs.gh_token }}" | gh auth login --with-token
5275

gh_app_credential_helper.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
if [ "$DEBUG_COMMANDS" = "true" ]; then
4+
set -ex
5+
fi
6+
7+
# DEBUG_MODE_ENABLED provides a way to enable the debug mode
8+
# export DEBUG_MODE=true
9+
DEBUG_MODE_ENABLED="${DEBUG_MODE:-false}"
10+
11+
APP_SIGN_KEY="$1"
12+
APP_ID="$2"
13+
APP_INSTALLATION_ID="$3"
14+
15+
TOKEN_IAT="$( date +%s )"
16+
TOKEN_EXP="$((TOKEN_IAT + 570))"
17+
18+
RAW_TOKEN_HEADER='{"alg":"RS256"}'
19+
TOKEN_HEADER=$( echo -n "${RAW_TOKEN_HEADER}" | openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n' )
20+
21+
RAW_TOKEN_PAYLOAD="{\"iat\":${TOKEN_IAT},\"exp\":${TOKEN_EXP},\"iss\":\"${APP_ID}\"}"
22+
TOKEN_PAYLOAD=$( echo -n "${RAW_TOKEN_PAYLOAD}" | openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n' )
23+
24+
TOKEN_BODY="${TOKEN_HEADER}.${TOKEN_PAYLOAD}"
25+
TOKEN_SIGNATURE=$( openssl dgst -sha256 -sign <(echo -n "${APP_SIGN_KEY}") <(echo -n "${TOKEN_BODY}") | openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n' )
26+
27+
GH_APP_TOKEN="${TOKEN_BODY}.${TOKEN_SIGNATURE}"
28+
29+
GH_APP_INSTALLATION_TOKEN=$(curl -XPOST -H "Authorization: Bearer $GH_APP_TOKEN" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/app/installations/$APP_INSTALLATION_ID/access_tokens" | jq -r .token)
30+
31+
echo "$GH_APP_INSTALLATION_TOKEN"

0 commit comments

Comments
 (0)