Skip to content

Commit

Permalink
ci: configure signed commits for conventional versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
tscpp committed Jun 24, 2024
1 parent 42d3519 commit 76251a1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
32 changes: 32 additions & 0 deletions .github/scripts/configure-git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { $ } from "execa";
import { appendFile } from "node:fs/promises";

const email = "928067+conventional-versioning[bot]@users.noreply.github.com";
const name = "Conventional Versioning";

const { GITHUB_TOKEN, GPG_KEY_ID, GPG_PRIVATE_KEY, GPG_PASSPHRASE } =
process.env;

// Configure credentials
await $`git config --global user.email ${email}`;
await $`git config --global user.name ${name}`;

// Add token to git credentials
await $`git config --global credential.helper store`;
await appendFile(
"~/.git-credentials",
`https://x-access-token:${GITHUB_TOKEN}@github.com\n`,
{ flag: "a+" },
);

// Setup GPG
await $`echo ${GPG_PRIVATE_KEY} | gpg --import`;
await $`echo "default-key ${GPG_KEY_ID}" >> ~/.gnupg/gpg.conf`;
await $`echo "use-agent" >> ~/.gnupg/gpg.conf`;
await $`echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf`;
await $`echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf`;
await $`gpg --batch --yes --passphrase ${GPG_PASSPHRASE} --quick-set-expire ${GPG_KEY_ID} 1y`;

// Configure commit signing
await $`git config --global user.signingkey ${GPG_KEY_ID}`;
await $`git config --global commit.gpgSign true`;
7 changes: 0 additions & 7 deletions .github/scripts/setup-git-user.js

This file was deleted.

11 changes: 8 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ jobs:
- name: Publish packages
run: pnpm nx release publish

- name: Setup Git User
run: node .github/scripts/setup-git-user.js

- name: Generate JWT and Get Installation Access Token
id: auth
run: |
Expand All @@ -71,6 +68,14 @@ jobs:
echo "TOKEN=${INSTALLATION_TOKEN}" >> $GITHUB_ENV
- name: Configure Git
run: node .github/scripts/configure-git.js
env:
GITHUB_TOKEN: ${{ env.TOKEN }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_ID: ${{ vars.GPG_KEY_ID }}

- name: Create Release Pull Request
run: node .github/scripts/create-versioning-pull-request.js
env:
Expand Down

0 comments on commit 76251a1

Please sign in to comment.