Skip to content

Commit 2c28466

Browse files
committed
feat: make the semantic release workflow reusable
1 parent 0dfe624 commit 2c28466

2 files changed

Lines changed: 98 additions & 3 deletions

File tree

.github/workflows/semantic-release.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ on:
44
push:
55
branches:
66
- main
7+
workflow_call:
8+
inputs:
9+
GH_APP_ID:
10+
type: string
11+
required: false
12+
secrets:
13+
GH_APP_PEM_FILE:
14+
required: false
715

816
concurrency:
917
group: release-${{ github.ref }}
@@ -18,9 +26,17 @@ jobs:
1826
issues: write
1927
pull-requests: write
2028
steps:
29+
- name: Create GitHub App token
30+
uses: actions/create-github-app-token@v3
31+
id: gh-app-token
32+
if: ${{ inputs.GH_APP_ID && secrets.GH_APP_PEM_FILE }}
33+
with:
34+
app-id: ${{ inputs.GH_APP_ID }}
35+
private-key: ${{ secrets.GH_APP_PEM_FILE }}
2136
- name: Checkout repository
2237
uses: actions/checkout@v6
2338
with:
39+
token: ${{ steps.gh-app-token.outputs.token || secrets.GITHUB_TOKEN }}
2440
fetch-depth: 0
2541
- name: Set up Node.js
2642
uses: actions/setup-node@v6
@@ -37,5 +53,5 @@ jobs:
3753
run: npm audit signatures
3854
- name: Run Semantic Release
3955
env:
40-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
GITHUB_TOKEN: ${{ steps.gh-app-token.outputs.token || secrets.GITHUB_TOKEN }}
4157
run: npx semantic-release

README.md

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,88 @@ A collection of GitHub composite actions and reusable workflows
66

77
- [Semantic Release Workflow](#semantic-release-workflow)
88

9-
### Semantic Release Workflow
9+
### Reusable Semantic Release Workflow
1010

11-
[Semantic Release workflow](.github/workflows/semantic-release.yaml) using the Conventional Commits preset to automate versioning, generates [GitHub releases](https://github.com/bruzit/github-actions-and-workflows/releases), and updates the [CHANGELOG](CHANGELOG.md).
11+
Reusable [Semantic Release workflow](.github/workflows/semantic-release.yaml) using the Conventional Commits preset to automate versioning, generates [GitHub releases](https://github.com/bruzit/github-actions-and-workflows/releases), and updates the [CHANGELOG](CHANGELOG.md).
12+
13+
## Usage
14+
15+
### Use Semantic Release Workflow
16+
17+
Create a workflow, for example, `.github/workflows/semantic-release.yaml`:
18+
19+
```yaml
20+
---
21+
name: Semantic Release
22+
23+
on:
24+
push:
25+
branches:
26+
- main
27+
28+
jobs:
29+
release:
30+
name: Release
31+
uses: bruzit/github-actions-and-workflows/.github/workflows/semantic-release.yaml@v0.2.0
32+
with:
33+
GH_APP_ID: ${{ vars.GH_APP_SEM_REL_ID }}
34+
secrets:
35+
GH_APP_PEM_FILE: ${{ secrets.GH_APP_SEM_REL_PEM_FILE }}
36+
```
37+
38+
To create a GitHub App and a GitHub App Installation:
39+
40+
- GitHub
41+
- _Organization_ / Settings / Developer settings / GitHub Apps
42+
- **New GitHub App**
43+
- Create GitHub App
44+
- GitHub App name: _name_
45+
- Description: _description_
46+
- Homepage URL: _homepage URL_
47+
- Webhook
48+
- Active: off
49+
- Permissions
50+
- Organization permissions
51+
- Contents: Read and write
52+
- Issues: Read and write
53+
- Pull requests: Read and write
54+
- Where can this GitHub App be installed?: _choose what suits you best_
55+
- **Create GitHub App**
56+
- _your app_
57+
- General
58+
- **Generate a private key**
59+
- Install App
60+
- _your organization_: **Install**
61+
- _Repository_ / Settings / Secrets and variables / Actions
62+
- Secrets
63+
- Repository secrets / **New repository secret**
64+
- Name: `GH_APP_PEM_FILE`
65+
- Secret: _content of the PEM file_
66+
- **Add secret**
67+
- Variables
68+
- Repository variables / **New repository variable**
69+
- Name: `GH_APP_ID`
70+
- Value: _GitHub App ID_
71+
- **Add variable**
72+
73+
Configure Semantic Release in the repository, for example, `.releaserc.yaml`:
74+
75+
```yaml
76+
---
77+
branches:
78+
- main
79+
plugins:
80+
- - "@semantic-release/commit-analyzer"
81+
- preset: conventionalcommits
82+
- - "@semantic-release/release-notes-generator"
83+
- preset: conventionalcommits
84+
- "@semantic-release/github"
85+
- - "@semantic-release/changelog"
86+
- changelogTitle: '# Changelog'
87+
- - "@semantic-release/git"
88+
- assets:
89+
- CHANGELOG.md
90+
```
1291

1392
## Copyright and Licensing
1493

0 commit comments

Comments
 (0)