Skip to content

Commit 512f3d9

Browse files
committed
readme update
1 parent e3d9f3c commit 512f3d9

File tree

1 file changed

+86
-5
lines changed

1 file changed

+86
-5
lines changed

README.md

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ Offered as node module and CLI tool.
1414

1515
- Automate the process of committing file additions, changes, or deletions to a GitHub repository without cloning it locally
1616
- Integrate with existing CI/CD pipelines perform signed commits on behalf of the pipeline, without hard-to-setup GPG config
17-
- Avoid storing private SSH keys in CI/CD environments (only the GITHUB_TOKEN is needed and can be easily saved as secret string passed as environment variable at pipeline runtime)
17+
- Avoid storing private SSH keys in CI/CD environments (only the `GITHUB_TOKEN` is needed and can be easily saved as secret string passed as environment variable at pipeline runtime)
1818
- you name it...
1919

20+
I have actually written this to get signed commits in GitHub Actions running [here](https://github.com/pirafrank/fpiracom).
21+
2022
## ⚠️ Before you start
2123

24+
- `GITHUB_TOKEN` must be set as environment variable. It must have write access to the repository you want to commit to
2225
- Changed (or new) files must exist locally
2326
- for practial reasons, those files must have the same file name and file path as the ones in the repository you are replacing with your commit (or the same file name and file path you want them to have in the repository)
2427
- Deleted files may not exist locally, and their path may just be provided as argument
@@ -38,7 +41,9 @@ Note: in GitHub Actions the `GITHUB_TOKEN` is automatically generated per each r
3841
npm install
3942
```
4043

41-
## Usage examples
44+
## CLI
45+
46+
### Usage examples
4247

4348
```sh
4449
export GITHUB_TOKEN='your_github_token_here'
@@ -60,21 +65,97 @@ node github.js commit \
6065
--commitMessage 'remove .gitignore'
6166
```
6267

68+
Multi-file commit is also possible:
69+
70+
- `--changed` and `--deleted` may have multiple file paths, as a single string with space-separated values, or by repeating the option per each file path. All file paths must be relative to the repository root.
71+
6372
```sh
6473
export GITHUB_TOKEN='your_github_token_here'
6574
node github.js commit \
6675
--owner yourname \
6776
--repo some_repo_of_yours \
6877
--branch main \
69-
--changed 'some_dir/some_file.txt' \
70-
--changed 'some_other_dir/some_other_file.txt' \
78+
--changed 'some_dir/some_file.txt' 'some_other_dir/some_other_file.txt' \
7179
--deleted 'some_dir/delete_me.txt' \
80+
--deleted 'some_dir/subdir/delete_me_too.txt' \
7281
--commitMessage 'stuff'
7382
```
7483

84+
Use `--help` for a full list of available commands and options.
85+
86+
## `npm` module
87+
88+
The module exports the following functions:
89+
90+
- `createCommitOnBranch`
91+
- `checkIfBranchExists`
92+
- `getShaOfParentCommit`
93+
94+
Before using any of them, you must call the `init` function with the `GITHUB_TOKEN` and the GitHub GraphQL URL as arguments.
95+
96+
```js
97+
init("your_github_token_here", "https://api.github.com/graphql");
98+
```
99+
100+
If called without arguments, it will use the `GITHUB_TOKEN` and `GITHUB_GRAPHQL_URL` environment variables.
101+
102+
```js
103+
init();
104+
```
105+
106+
Please refer to `index.js` for the function signatures.
107+
108+
## GitHub Action usage
109+
110+
You can use this module as a GitHub Action. It is a Docker-based action.
111+
112+
### Print help
113+
114+
```yaml
115+
# Print help
116+
- name: Print graphQL client help
117+
uses: pirafrank/github-graphql-client@v1
118+
with:
119+
args: "--help"
120+
```
121+
122+
### Commit changes
123+
124+
Requirements when running in a GitHub Actions workflow:
125+
126+
- `--changed` and `--deleted` may have multiple file paths, as a single string with space-separated values, or by repeating the option per each file path. All file paths must be relative to the repository root.
127+
- `GITHUB_TOKEN` must be set in the environment variables with write access to the repository. Go to *Repository Settings > Actions > General > Workflow permissions*, and set `Read and write permissions`.
128+
129+
To commit to other repositories, you may need to override the default `GITHUB_TOKEN` with a personal access token with the `repo` scope. Go to *Profile > Settings > Developer settings > Personal access tokens > Token (classic)*, and Generate new token (classic) with the full-control over `repo` scope. Tip: store the generated token in repository secrets.
130+
131+
```yaml
132+
# Commit changes...
133+
- name: Commit changes
134+
id: commit_changes
135+
uses: pirafrank/github-graphql-client@v1
136+
if: ${{ vars.RUN_COMMIT_CHANGES == 'true' }}
137+
env:
138+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
with:
140+
args: "commit --owner=${{ github.repository_owner }} --repo=${{ github.event.repository.name }} --branch=${{ github.ref_name }} --commitMessage='this is a webflow signed commit' --changed new.txt dummy/subdir/changed.txt --deleted dummy/delete_me.txt another_deleted.txt"
141+
# ...then use output details in another step
142+
- name: Print git commit output
143+
if: ${{ vars.RUN_COMMIT_CHANGES == 'true' }}
144+
run: |
145+
echo "Run command: ${{ steps.commit_changes.outputs.command }}"
146+
echo "Commit URL: ${{ steps.commit_changes.outputs.commitUrl }}"
147+
148+
```
149+
150+
Tip: you may create the strings with the list of added and changed files from a previous step in your workflow.
151+
152+
### Other commands
153+
154+
The action accepts the same commands you can provied to the CLI. Pass them as a single string to the `args` input.
155+
75156
## Tests
76157

77-
Create a `.env` file with your `GITHUB_TOKEN`, then run:
158+
Create a `.env` file with your `repo`-scoped `GITHUB_TOKEN`, then run:
78159

79160
```sh
80161
npm test

0 commit comments

Comments
 (0)