Skip to content

Commit 6c4a5d4

Browse files
committed
build: add workflow to generate Git note
1 parent ccef32f commit 6c4a5d4

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2024 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# Workflow name:
20+
name: git_note_amend_message
21+
22+
# Workflow triggers:
23+
on:
24+
# Allow the workflow to be manually run:
25+
workflow_dispatch:
26+
# Define the input parameters for the workflow:
27+
inputs:
28+
commit_hash:
29+
description: 'Commit hash to create note for'
30+
required: true
31+
type: string
32+
message:
33+
description: 'New commit message'
34+
required: true
35+
type: string
36+
37+
# Allow the workflow to be triggered by other workflows:
38+
workflow_call:
39+
# Define the input parameters for the workflow:
40+
inputs:
41+
commit_hash:
42+
description: 'Commit hash to create note for'
43+
required: true
44+
type: string
45+
message:
46+
description: 'New commit message'
47+
required: true
48+
type: string
49+
50+
# Define the secrets accessible by the workflow:
51+
secrets:
52+
STDLIB_BOT_GITHUB_TOKEN:
53+
description: 'GitHub token for stdlib-bot'
54+
required: true
55+
REPO_GITHUB_TOKEN:
56+
description: 'GitHub token for accessing the repository'
57+
required: true
58+
STDLIB_BOT_GPG_PRIVATE_KEY:
59+
description: 'GPG private key for stdlib-bot'
60+
required: true
61+
STDLIB_BOT_GPG_PASSPHRASE:
62+
description: 'GPG passphrase for stdlib-bot'
63+
required: true
64+
65+
# Workflow jobs:
66+
jobs:
67+
68+
# Define a job to create a Git note amending a commit message:
69+
create_git_note:
70+
71+
# Define job name:
72+
name: 'Create Git Note Amending Commit Message'
73+
74+
# Define the type of virtual host machine:
75+
runs-on: ubuntu-latest
76+
77+
# Define the sequence of job steps:
78+
steps:
79+
# Checkout the repository:
80+
- name: 'Checkout repository'
81+
# Pin action to full length commit SHA
82+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
83+
with:
84+
# Fetch only the latest commit:
85+
fetch-depth: 1
86+
87+
# Token for accessing the repository:
88+
token: ${{ secrets.REPO_GITHUB_TOKEN }}
89+
90+
# Verify commit exists:
91+
- name: 'Verify commit exists'
92+
run: |
93+
if ! git rev-parse --quiet --verify ${{ inputs.commit_hash }}^{commit}; then
94+
echo "Error: Commit ${{ inputs.commit_hash }} not found"
95+
exit 1
96+
fi
97+
98+
# Create Git note:
99+
- name: 'Create Git note'
100+
run: |
101+
# Create Git note file:
102+
cat > "docs/git-notes/${{ inputs.commit_hash }}.txt" << EOF
103+
---
104+
type: amend-message
105+
---
106+
${{ inputs.message }}
107+
EOF
108+
109+
# Create step summary:
110+
echo "## Note for commit ${{ inputs.commit_hash }}:" >> $GITHUB_STEP_SUMMARY
111+
cat "docs/git-notes/${{ inputs.commit_hash }}.txt" >> $GITHUB_STEP_SUMMARY
112+
113+
# Disable Git hooks:
114+
- name: 'Disable Git hooks'
115+
run: |
116+
rm -rf .git/hooks
117+
118+
# Import GPG key to sign commits:
119+
- name: 'Import GPG key to sign commits'
120+
# Pin action to full length commit SHA
121+
uses: crazy-max/ghaction-import-gpg@cb9bde2e2525e640591a934b1fd28eef1dcaf5e5 # v6.2.0
122+
with:
123+
gpg_private_key: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
124+
passphrase: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}
125+
git_user_signingkey: true
126+
git_commit_gpgsign: true
127+
128+
# Commit and push changes:
129+
- name: 'Commit and push changes'
130+
env:
131+
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
132+
USER_NAME: stdlib-bot
133+
run: |
134+
git config --local user.email "[email protected]"
135+
git config --local user.name "${USER_NAME}"
136+
137+
git add "docs/git-notes/${{ inputs.commit_hash }}.txt"
138+
git commit -m "docs: add Git note for commit ${{ inputs.commit_hash }}"
139+
git push

0 commit comments

Comments
 (0)