Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b298cc6

Browse files
committedAug 17, 2023
Add a README
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 958519c commit b298cc6

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
 

‎README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# GitGitGadget's GitHub App
2+
3+
The purpose of GitGitGadget's GitHub App is two-fold:
4+
5+
- It acts upon GitHub webhook events, sent by GitHub
6+
- It allows GitGitGadget to act as the App, adding PR comments and pushing tags in the respective GitHub workflows
7+
8+
## Tips & Tricks for developing this GitHub App
9+
10+
### Debug/test-run as much Javascript via the command-line as possible
11+
12+
The easiest, and quickest, way to test most of the Javascript code is to run it on the command-line, via `node`.
13+
14+
To facilitate that, future functionality will be implemented in individually-testable modules as possible.
15+
16+
### Run the Azure Function locally
17+
18+
It is tempting to try to develop the Azure Function part of this GitHub App directly in the Azure Portal, but it is cumbersome and slow, and also impossibly unwieldy once the Azure Function has been deployed via GitHub (because that disables editing the Javascript code in the Portal).
19+
20+
Instead of pushing the code to Azure all the time, waiting until it is deployed, reading the logs, then editing the code, committing and starting another cycle, it is much, much less painful to develop the Azure Function locally.
21+
22+
To this end, [install the Azure Functions Core Tools (for performance, use Linux)](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=v4%2Clinux%2Ccsharp%2Cportal%2Cbash#install-the-azure-functions-core-tools, e.g. via [WSL](https://learn.microsoft.com/en-us/windows/wsl/)).
23+
24+
Then, configure [the `GITHUB_WEBHOOK_SECRET` variable](#some-environment-variables) locally, via [a `local.settings.json` file](https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-local#local-settings-file). The contents would look like this:
25+
26+
```json
27+
{
28+
"IsEncrypted": false,
29+
"Values": {
30+
"FUNCTIONS_WORKER_RUNTIME": "node",
31+
"AzureWebJobsStorage": "<storage-key>",
32+
"GITHUB_WEBHOOK_SECRET": "<webhook-secret>"
33+
},
34+
"Host": {
35+
"LocalHttpPort": 7071,
36+
"CORS": "*",
37+
"CORSCredentials": false
38+
}
39+
}
40+
```
41+
42+
Finally, [run the Function locally](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=v4%2Clinux%2Cnode%2Cportal%2Cbash#start) by calling `func start` on the command-line.
43+
44+
You can also run/debug it via VS Code, there is a default configuration called "Attach to Node Functions".
45+
46+
## How this GitHub App was set up
47+
48+
This process looks a bit complex, the main reason for that being that three things have to be set up essentially simultaneously: an Azure Function, a GitHub repository and a GitHub App.
49+
50+
### The Azure Function
51+
52+
First of all, a new [Azure Function](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Web%2Fsites/kind/functionapp) was created. A Linux one was preferred, for cost and performance reasons. Deployment with GitHub was _not_ yet configured.
53+
54+
#### Getting the "publish profile"
55+
56+
After the deployment succeeded, in the "Overview" tab, there is a "Get publish profile" link on the right panel at the center top. Clicking it will automatically download a `.json` file whose contents will be needed later.
57+
58+
#### Some environment variables
59+
60+
A few environment variables will have to be configured for use with the Azure Function. This can be done on the "Configuration" tab, which is in the "Settings" group.
61+
62+
Concretely, the environment variables `GITHUB_WEBHOOK_SECRET` and `GITGITGADGET_TRIGGER_TOKEN` (a Personal Access Token to trigger the Azure Pipelines) need to be set. For the first, a generated random string was used. The second one was [created](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows#create-a-pat) scoped to the Azure DevOps project `gitgitgadget` with the Build (read & execute) permissions.
63+
64+
### The repository
65+
66+
On https://github.com/, the `+` link on the top was pressed, and an empty, private repository was registered. Nothing was pushed to it yet.
67+
68+
After that, the contents of the publish profile that [was downloaded earlier](#getting-the-publish-profile) were registered as Actions secret, under the name `AZURE_FUNCTIONAPP_PUBLISH_PROFILE`.
69+
70+
This repository was initialized locally by forking https://github.com/gitgitgadget/gitgitgadget and separating out the Azure Functions part of it. Then, the test suite was developed and the GitHub workflows were adapted from https://github.com/git-for-windows/gfw-helper-github-app. After that, the `origin` remote was set to the newly registered repository on GitHub.
71+
72+
As a last step, the repository was pushed, triggering the deployment to the Azure Function.
73+
74+
### The GitHub App
75+
76+
Finally, the existing GitHub App's webhook URL was redirected to the new one. If there had not been an existing GitHub App, [a new GitHub App would have been registered](https://github.com/settings/apps/new) with the repository URL on GitHub as homepage URL.
77+
78+
As Webhook URL, the URL of the Azure Function was used, which can be copied in the "Functions" tab of the Azure Function. It looks similar to this: https://my-github-app.azurewebsites.net/api/MyGitHubApp
79+
80+
The value stored in the Azure Function as `GITHUB_WEBHOOK_SECRET` was used as Webhook secret.
81+
82+
The GitGitGadget GitHub app requires the following permissions: Read access to metadata, and Read and write access to checks, code, commit statuses, issues, pull requests, and workflows.

0 commit comments

Comments
 (0)
Please sign in to comment.