You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -21,33 +31,107 @@ I have actually written this to get signed commits in GitHub Actions running [he
21
31
22
32
## ⚠️ Before you start
23
33
24
-
-`GITHUB_TOKEN` must be set as environment variable. It must have write access to the repository you want to commit to
34
+
### About `GITHUB_TOKEN`
35
+
36
+
In GitHub Actions the `GITHUB_TOKEN` is [automatically generated](https://docs.github.com/en/actions/security-guides/automatic-token-authentication) per each run and is available as an environment variable. For the commit action to work, the `GITHUB_TOKEN` must be set as environment variable and it must have *write* access to the repository you want to commit to.
37
+
38
+
The following applies, based on the context you are running the action in:
39
+
40
+
-**GitHub Actions**: If the repository is the same where your workflow run, you can either:
41
+
- Configure it by adding the following to your workflow YAML file (restricted priviledges, recommended):
42
+
43
+
```yaml
44
+
permissions:
45
+
contents: write
46
+
```
47
+
48
+
- Set it up for all workflows in your repository (wider priviledges, not recommended): Go to *Repository Settings > Actions > General > Workflow permissions*, and set `Read and write permissions`.
49
+
50
+
- **GitHub Actions**: if you need 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.
51
+
- **Tip**: store the generated token in repository secrets!
52
+
- **Docker image, npm module, or CLI**: when running outside of GitHub Actions, set an environment variable called `GITHUB_TOKEN` with the token value having full-control over `repo` scope.
53
+
54
+
### Usage assumptions
55
+
25
56
- Changed (or new) files must exist locally
26
57
- 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)
27
58
- Deleted files may not exist locally, and their path may just be provided as argument
28
59
- GraphQL APIs are not meant to be used to push a lot of code! If that is your case, please consider using a local clone and `git`.
29
60
30
-
## Requirements
61
+
## GitHub Action usage
62
+
63
+
You can use this module as a GitHub Action. It is a Docker-based action.
64
+
65
+
### Print help
66
+
67
+
```yaml
68
+
# Print help
69
+
- name: Print help
70
+
uses: pirafrank/github-commit-sign@v0
71
+
with:
72
+
args: "--help"
73
+
```
74
+
75
+
### Commit changes
76
+
77
+
Requirements when running in a GitHub Actions workflow:
78
+
79
+
- `GITHUB_TOKEN`must be set as environment variable and it must have write access to the repository you want to commit to. Read the *Before you start* section above for more details.
80
+
- `--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.
81
+
82
+
```yaml
83
+
# Commit changes...
84
+
- name: Commit changes
85
+
id: commit_changes
86
+
uses: pirafrank/github-commit-sign@v0
87
+
if: ${{ vars.RUN_COMMIT_CHANGES == 'true' }}
88
+
env:
89
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90
+
with:
91
+
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"
> You may want to create string format list of added and changed files in a previous step in your workflow.
103
+
104
+
### Other commands
105
+
106
+
The action accepts the same commands you can provide to the CLI. Pass them as a single string to the `args` input. Read below for more details.
31
107
32
-
- Node.js (18+)
108
+
## Docker image
109
+
110
+
You can use this module as a Docker image. It is a multi-arch image, so it should run on any architecture.
111
+
112
+
The image is available on Docker Hub as `pirafrank/github-commit-sign`.
113
+
114
+
The image run the CLI instance of the program, thus accepting the same commands you can provide to the CLI. Pass them as you'd do with any other Docker image.
115
+
116
+
## CLI usage
117
+
118
+
### Requirements
119
+
120
+
- Node.js (18.18+)
33
121
- A GitHub token with the `repo` scope.
34
122
- The token must be set in the environment variable called `GITHUB_TOKEN`.
35
123
36
-
Note: in GitHub Actions the `GITHUB_TOKEN` is automatically generated per each run and is available as an environment variable. More info [here](https://docs.github.com/en/actions/security-guides/automatic-token-authentication).
37
-
38
-
## Installation
124
+
### Installation
39
125
40
126
```sh
41
-
npm install
127
+
npm install -g @pirafrank/github-commit-sign
42
128
```
43
129
44
-
## CLI
45
-
46
130
### Usage examples
47
131
48
132
```sh
49
133
export GITHUB_TOKEN='your_github_token_here'
50
-
node github.js commit \
134
+
ggh commit \
51
135
--owner yourname \
52
136
--repo some_repo_of_yours \
53
137
--branch main \
@@ -57,7 +141,7 @@ node github.js commit \
57
141
58
142
```sh
59
143
export GITHUB_TOKEN='your_github_token_here'
60
-
node github.js commit \
144
+
ggh commit \
61
145
--owner yourname \
62
146
--repo some_repo_of_yours \
63
147
--branch main \
@@ -71,7 +155,7 @@ Multi-file commit is also possible:
71
155
72
156
```sh
73
157
export GITHUB_TOKEN='your_github_token_here'
74
-
node github.js commit \
158
+
ggh commit \
75
159
--owner yourname \
76
160
--repo some_repo_of_yours \
77
161
--branch main \
@@ -105,54 +189,6 @@ init();
105
189
106
190
Please refer to `index.js` for the function signatures.
107
191
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 help
117
-
uses: pirafrank/github-commit-sign@v0
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-commit-sign@v0
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"
0 commit comments