Skip to content

Commit 0e9fb23

Browse files
committed
feat: publish also as multi-arch docker image
1 parent 096b7fc commit 0e9fb23

File tree

3 files changed

+128
-63
lines changed

3 files changed

+128
-63
lines changed

.github/workflows/pr.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,22 @@ jobs:
5353
# docs: https://github.com/marketplace/actions/build-and-push-docker-images
5454
- name: Set up QEMU
5555
uses: docker/setup-qemu-action@v3
56+
with:
57+
platforms: linux/amd64,linux/arm64
5658

5759
- name: Set up Docker Buildx
5860
uses: docker/setup-buildx-action@v3
5961

6062
# docs: https://docs.docker.com/build/ci/github-actions/test-before-push/
6163
- name: Build Docker image
62-
uses: docker/build-push-action@v5
64+
uses: docker/build-push-action@v6
6365
with:
6466
push: false
6567
context: .
68+
file: Dockerfile
69+
platforms: linux/amd64,linux/arm64
6670
load: true
67-
tags: github-commit-sign:latest
71+
tags: ${{ github.repository }}:latest
6872

6973
- name: Run Docker tests
7074
env:

.github/workflows/release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ jobs:
2929
- name: Install dependencies
3030
run: npm ci
3131

32+
- name: Login to DockerHub
33+
uses: docker/login-action@v3
34+
with:
35+
username: ${{ secrets.DOCKERHUB_USERNAME }}
36+
password: ${{ secrets.DOCKERHUB_TOKEN }}
37+
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@v3
40+
with:
41+
platforms: linux/amd64,linux/arm64
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v3
45+
-
46+
name: Build and push
47+
uses: docker/build-push-action@v6
48+
with:
49+
push: true
50+
tags: ${{ github.repository }}:latest,${{ github.repository }}:${{ github.event.release.tag_name }}
51+
context: .
52+
file: Dockerfile
53+
platforms: linux/amd64,linux/arm64
54+
55+
# publish to npm after docker image is built and pushed.
56+
# this to avoid publishing to npm registry before a possible docker image build failure
3257
- name: Publish to npm
3358
run: npm publish --provenance --access public
3459
env:

README.md

Lines changed: 97 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# GitHub Commit Sign
22

3+
[![GitHub release](https://img.shields.io/github/release/pirafrank/github-commit-sign.svg?style=flat-square)](https://github.com/pirafrank/github-commit-sign/releases/latest)
4+
[![GitHub marketplace](https://img.shields.io/badge/marketplace-github--commit--sign-blue?logo=github&style=flat-square)](https://github.com/marketplace/actions/github-commit-sign)
5+
[![Docker pulls](https://img.shields.io/docker/pulls/pirafrank/github-commit-sign.svg?style=flat-square)](https://hub.docker.com/r/pirafrank/github-commit-sign)
6+
[![npm](https://img.shields.io/npm/v/@pirafrank/github-commit-sign.svg?style=flat-square)](https://www.npmjs.com/package/@pirafrank/github-commit-sign)
7+
38
A thin wrapper to perform signed commits to a GitHub repository through their GraphQL APIs. Useful to create signed commits in CI/CD environments.
49

5-
Offered as node module and CLI tool.
10+
## Available as
11+
12+
- [GitHub Action](https://github.com/marketplace/actions/github-commit-sign)
13+
- [Docker image](https://hub.docker.com/r/pirafrank/github-commit-sign)
14+
- [CLI tool](#cli-usage)
15+
- [npm module](https://www.npmjs.com/package/@pirafrank/github-commit-sign)
616

717
## Why
818

@@ -21,33 +31,107 @@ I have actually written this to get signed commits in GitHub Actions running [he
2131

2232
## ⚠️ Before you start
2333

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+
2556
- Changed (or new) files must exist locally
2657
- 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)
2758
- Deleted files may not exist locally, and their path may just be provided as argument
2859
- 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`.
2960

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"
92+
# ...then use output details in another step
93+
- name: Print git commit output
94+
if: ${{ vars.RUN_COMMIT_CHANGES == 'true' }}
95+
run: |
96+
echo "Run command: ${{ steps.commit_changes.outputs.command }}"
97+
echo "Commit URL: ${{ steps.commit_changes.outputs.commitUrl }}"
98+
99+
```
100+
101+
> [!TIP]
102+
> 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.
31107

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+)
33121
- A GitHub token with the `repo` scope.
34122
- The token must be set in the environment variable called `GITHUB_TOKEN`.
35123

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
39125

40126
```sh
41-
npm install
127+
npm install -g @pirafrank/github-commit-sign
42128
```
43129

44-
## CLI
45-
46130
### Usage examples
47131

48132
```sh
49133
export GITHUB_TOKEN='your_github_token_here'
50-
node github.js commit \
134+
ggh commit \
51135
--owner yourname \
52136
--repo some_repo_of_yours \
53137
--branch main \
@@ -57,7 +141,7 @@ node github.js commit \
57141

58142
```sh
59143
export GITHUB_TOKEN='your_github_token_here'
60-
node github.js commit \
144+
ggh commit \
61145
--owner yourname \
62146
--repo some_repo_of_yours \
63147
--branch main \
@@ -71,7 +155,7 @@ Multi-file commit is also possible:
71155

72156
```sh
73157
export GITHUB_TOKEN='your_github_token_here'
74-
node github.js commit \
158+
ggh commit \
75159
--owner yourname \
76160
--repo some_repo_of_yours \
77161
--branch main \
@@ -105,54 +189,6 @@ init();
105189

106190
Please refer to `index.js` for the function signatures.
107191

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"
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-
156192
## Tests
157193

158194
Create a `.env` file with your `repo`-scoped `GITHUB_TOKEN`, then run:

0 commit comments

Comments
 (0)