Skip to content

Commit d2c3fa5

Browse files
Allow to Use Custom Git Actor for Bundled JS Output (#14)
* feat: allow to use custom actor * chore: new inputs * docs: add tutorial section * chore: minor doc fix * chore: remove unused `github_token` input
1 parent 73c39c9 commit d2c3fa5

File tree

3 files changed

+81
-11
lines changed

3 files changed

+81
-11
lines changed

README.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
- uses: actions/checkout@master
2222
- uses: flarum/action-build@2
2323
with:
24-
github_token: ${{ secrets.GITHUB_TOKEN }}
2524
build_script: build # npm run build
2625
build_typings_script: build-typings # npm run build-typings
2726
test_script: test # npm run test
@@ -36,8 +35,7 @@ jobs:
3635
Here is a full list of options available using the `with` syntax:
3736

3837
| Name | Required | Description | Example | Default |
39-
|------------------------| -------- |-------------------------------------------------------------------------------------------------------------------------|-------------------------------| ------- |
40-
| `github_token` | Yes | Your Actions GitHub token. The example value should work for this by default. | `${{ secrets.GITHUB_TOKEN }}` | None |
38+
| ---------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ------- |
4139
| `build_script` | Yes | The `package.json` script to run to build your extension JS. | `build` | `build` |
4240
| `build_typings_script` | No | If defined, runs the script of this name in `package.json` to build typings for your extension. | `build-typings` | Unset |
4341
| `format_script` | No | If defined, runs the script of this name in `package.json` to check code formatting of your extension's JS. | `format-check` | Unset |
@@ -49,13 +47,81 @@ Here is a full list of options available using the `with` syntax:
4947
| `do_not_commit` | No | Set to `true` to NOT commit the built JS/Typings. Useful for validating JS source. | `false` | `false` |
5048
| `checks` | No | An array of strings, where each is a script that should be run before committing built js. | `false` | `false` |
5149
| `commit_all_dirty` | No | Set to `true` to commit all file changes, not just files in the dist JS directory. | `false` | `false` |
50+
| `git_actor_name` | No | Allows to set a different username (normally `flarum-bot`) for the actor which commits the bundles JS. | `acme-bot` | Unset |
51+
| `git_actor_email` | No | Allows to set a different email for the actor which commits the bundled JS. | `[email protected]` | Unset |
5252

5353
### Assumptions
5454

5555
Your Javascript must be in a `js` folder, similar to how Flarum core and Flarum's first-party extensions are laid out.
5656

5757
If building typings, we assume that they are built to `js/dist-typings`, as set in the example `tsconfig.json` found on the [flarum-tsconfig](https://github.com/flarum/flarum-tsconfig).
5858

59+
## Setting Up Custom Git Actor for Frontend Workflow
60+
61+
This guide helps you configure a custom Git actor in your extension's frontend workflow, specifically useful if your organization enforces branch protection rules requiring pull requests for changes to the default branch.
62+
63+
### Basic Configuration (Light Version)
64+
65+
To change the actor committing bundled JS in your workflow:
66+
67+
1. Add `git_actor_name` and `git_actor_email` inputs to your workflow file.
68+
2. These values can represent either a real GitHub user or a fictional one.
69+
3. If using a real user, it's recommended to use the GitHub-provided email for privacy-enabled accounts.
70+
71+
Example:
72+
73+
```yaml
74+
name: ACME Foobar JS
75+
76+
on: [workflow_dispatch, push, pull_request]
77+
78+
jobs:
79+
run:
80+
uses: flarum/framework/.github/workflows/[email protected]
81+
with:
82+
enable_prettier: true
83+
...
84+
git_actor_name: acme-bot
85+
git_actor_email: [email protected]
86+
```
87+
88+
### Advanced Configuration (With Branch Protection Rules)
89+
90+
If you also want to enforce branch protection and allow a custom actor to bypass pull requests:
91+
92+
1. Create a dedicated CI GitHub account with admin permissions in your organization.
93+
2. Generate a Personal Access Token for the CI account:
94+
95+
- Go to [GitHub Tokens](https://github.com/settings/tokens/new) and create a new token with repo and workflow scopes.
96+
97+
3. Add the token as a secret in your repository.
98+
4. Use the real CI account's username and email in your workflow.
99+
100+
When setting branch protection rules, make sure not to enable "Do not allow bypassing the above settings" as this would block automated commits from the CI actor.
101+
102+
```yml
103+
name: ACME Foobar JS
104+
105+
on: [workflow_dispatch, push, pull_request]
106+
107+
jobs:
108+
run:
109+
uses: flarum/framework/.github/workflows/[email protected]
110+
with:
111+
enable_prettier: true
112+
..
113+
git_actor_name: ci-bot
114+
git_actor_email: [email protected]
115+
116+
secrets:
117+
git_actor_token: ${{ secrets.GIT_ACTOR_TOKEN }}
118+
```
119+
120+
### Important Notes
121+
122+
- Avoid the "Do not allow bypassing the above settings" option when setting up branch protection, or your CI actor won’t be able to commit the bundled JS.
123+
- Make sure other rules or permissions don't block the CI account from making automated commits.
124+
59125
## Only Build on Master
60126

61127
If you only want to run the workflow when commits are pushed to the `master` branch, change `on: push` to the following:

action.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ runs:
55
using: 'node20'
66
main: 'dist/index.js'
77
inputs:
8-
github_token:
9-
description: 'Token used to push built JS code to your GitHub repository (if in doubt, use "(dollar-sign){{ secrets.GITHUB_TOKEN }}")'
10-
required: true
118
build_script:
129
description: The name of the package.json script to run to build your JS code
1310
default: 'build'
@@ -43,3 +40,9 @@ inputs:
4340
description: Set to `true` to commit all file changes, not just files in the dist JS directory.
4441
default: 'false'
4542
required: false
43+
git_actor_name:
44+
description: The name of the git actor to use for the bundled JS output.
45+
required: false
46+
git_actor_email:
47+
description: The email of the git actor to use for the bundled JS output.
48+
required: false

src/jobs/commitChangesToGit.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ export default async function commitChangesToGit(jp: FSJetpack): Promise<void> {
2424
maxConcurrentProcesses: 1,
2525
};
2626

27+
const gitActorName = core.getInput('git_actor_name', { required: false, trimWhitespace: true }) || 'flarum-bot';
28+
const gitActorEmail = core.getInput('git_actor_email', { required: false, trimWhitespace: true }) || '[email protected]';
29+
2730
const config = {
2831
author: {
29-
name: 'flarum-bot',
30-
32+
name: gitActorName,
33+
email: gitActorEmail,
3134
},
3235
};
3336

@@ -61,11 +64,9 @@ Includes transpiled JS/TS${core.getInput('build_typings_script') !== '' ? ', and
6164
6265
[skip ci]`);
6366

64-
const token = core.getInput('github_token', { required: true, trimWhitespace: true });
65-
6667
debugLog(`** Pushing commit`);
6768

68-
await git.addRemote('upstream', `https://${process.env.GITHUB_ACTOR}:${token}@github.com/${process.env.GITHUB_REPOSITORY}.git`);
69+
await git.addRemote('upstream', `https://github-actions:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`);
6970

7071
log(`${status}`);
7172

0 commit comments

Comments
 (0)