Skip to content

Commit 72213f5

Browse files
committed
ci: Use semantic release development workflow
1 parent 7a95a55 commit 72213f5

File tree

8 files changed

+186
-35
lines changed

8 files changed

+186
-35
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,5 @@ A clear and concise description of what you expected to happen.
2020
**Screenshots**
2121
If applicable, add screenshots to help explain your problem.
2222

23-
**Desktop (please complete the following information):**
24-
- OS: [e.g. iOS]
25-
- Browser [e.g. chrome, safari]
26-
- Version [e.g. 22]
27-
28-
**Smartphone (please complete the following information):**
29-
- Device: [e.g. iPhone6]
30-
- OS: [e.g. iOS8.1]
31-
- Browser [e.g. stock browser, safari]
32-
- Version [e.g. 22]
33-
3423
**Additional context**
3524
Add any other context about the problem here.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### Description
2+
3+
Describe what this pull request is about
4+
5+
6+
### Testing Instructions
7+
8+
1. Check out this pull request
9+
2. _Testing instructions here_
10+
11+
12+
### Checklist
13+
14+
- [ ] Does what the author says it will do
15+
- [ ] Testing instructions are provided
16+
- [ ] Commit messages make sense and follow the [conventional commit](https://www.conventionalcommits.org) standard
17+
- [ ] No identified security issues
18+
- [ ] No identified maintenance issues
19+
- [ ] Any third-party libraries/dependencies use the MIT or Apache 2.0 license
20+
- [ ] Changes made are backwards compatible and will not break existing setups
21+
- [ ] Changes to scripts in the `bin/` directory run correctly on both MacOS and WSL
22+
- [ ] Changes to containers can be built locally sucessfully (e.g. via `tbuild container && tup container`)
23+
- [ ] Containers/images are compatible with both AMD64 (Windows) and ARM64 (MacOS)
24+
- [ ] Changes made to `config.php` are compatible with our oldest supported Totara version, our newest Totara version, and Moodle
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'Check Conventional Commit In Pull Requests'
2+
description: 'Check that the PR title contains a valid task type and (optionally) a task number, and label the PR based on the task type'
3+
4+
inputs:
5+
commit-types:
6+
description: 'An array of commit types. Example: ["feat","fix","docs","test","ci","refactor","perf","chore","revert"]'
7+
required: true
8+
github-token:
9+
description: "GitHub token to authenticate requests"
10+
required: true
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '20'
19+
- name: Run Conventional Commit Checker
20+
run: |
21+
export COMMIT_TYPES='${{ inputs.commit-types }}'
22+
export GITHUB_TOKEN='${{ inputs.github-token }}'
23+
cd .github/actions/cc-checker
24+
npm install --no-save conventional-commits-parser@^3.2.4 @actions/core@^1.11.1 @actions/github@^6.0.1
25+
node cc-checker.js
26+
shell: bash
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const { setFailed } = require('@actions/core');
2+
const github = require('@actions/github');
3+
const commitParser = require('conventional-commits-parser');
4+
5+
async function run() {
6+
const commitTypesEnv = process.env.COMMIT_TYPES;
7+
if (!commitTypesEnv) {
8+
setFailed('COMMIT_TYPES not found in environment.');
9+
return;
10+
}
11+
let commitTypeList;
12+
try {
13+
commitTypeList = JSON.parse(commitTypesEnv);
14+
} catch (err) {
15+
setFailed('Invalid COMMIT_TYPES input. Expecting a JSON array.');
16+
return;
17+
}
18+
19+
const pr = github.context.payload.pull_request;
20+
if (!pr) {
21+
setFailed('No pull request found in context.');
22+
return;
23+
}
24+
25+
// Get the GitHub token from env
26+
const token = process.env.GITHUB_TOKEN;
27+
if (!token) {
28+
setFailed('GITHUB_TOKEN not found in environment.');
29+
return;
30+
}
31+
32+
const octokit = github.getOctokit(token);
33+
const { owner, repo } = github.context.repo;
34+
const prNumber = pr.number;
35+
36+
// Fetch all commits in the PR
37+
const commits = await octokit.rest.pulls.listCommits({
38+
owner,
39+
repo,
40+
pull_number: prNumber,
41+
});
42+
43+
let failed = false;
44+
let errors = [];
45+
for (const commit of commits.data) {
46+
const message = commit.commit.message.split('\n')[0].trim();
47+
const ast = commitParser.sync(message);
48+
const type = ast.type ? ast.type : '';
49+
if (!type || !commitTypeList.includes(type)) {
50+
failed = true;
51+
errors.push(`Commit ${commit.sha}: Invalid or missing commit type: '${type}'. Must be one of: ${commitTypeList.join(', ')}`);
52+
}
53+
}
54+
if (failed) {
55+
setFailed(errors.join('\n'));
56+
return;
57+
}
58+
return true;
59+
}
60+
61+
run().catch(err => setFailed(err.message));
62+
63+
module.exports = { run };
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Create Semantic Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
issues: write
17+
pull-requests: write
18+
id-token: write
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
- name: Set up Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 'lts/*'
28+
- name: Install dependencies
29+
run: npm install --no-save semantic-release@^24.2.9
30+
- name: Release
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
33+
run: npx semantic-release
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Conventional Commit Validation
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, edited]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
validate-commits:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
- name: Validate commits are Conventional Commits
19+
uses: ./.github/actions/cc-checker
20+
with:
21+
commit-types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert"]'
22+
github-token: ${{ secrets.GITHUB_TOKEN }}

.releaserc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
release:
2+
branches:
3+
- master
4+
5+
plugins:
6+
- "@semantic-release/commit-analyzer"
7+
- "@semantic-release/release-notes-generator"
8+
- "@semantic-release/github"

CONTRIBUTING.md

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,17 @@ We try to collect all improvements and bug reports as Issues. Also we avoid push
88

99
## Workflow
1010

11-
We follow the [GitFlow Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow).
12-
13-
## Standard workflow
14-
15-
If you want to add a new feature or fix a bug
11+
If you want to add a new feature or fix a bug:
1612

1713
1. Fork the repository
18-
2. Check out the **develop** branch `git checkout develop`
19-
3. Create a new feature or bugfix branch `git checkout -b feature-upgrade-nodejes` (prefix with **feature**- or **bugfix**- and name it with something meaningful)
20-
4. Create and push your commits into your own repository
21-
5. Create a new Pull Request for your branch pointing to **develop**. Don't point it to **master** directly.
22-
23-
When enough features come together we will merge develop into master, create a new tag and publish it as a new release. With this approach the master will always contain the latest stable version.
24-
25-
## Hotfixes
26-
27-
If something critical needs to be fixed and released please
28-
29-
1. Create a hotfix branch (prefix with hotfix- and name it properly) based on the current master
30-
2. Fix the code
31-
3. Create a new Pull Request from your hotfix branch pointing it to **master**
32-
4. Once it got reviewed and merged we will merge master back into develop to make sure it's in sync.
33-
34-
## Unstable releases
14+
2. Check out the latest **master** branch `git checkout master && git pull`
15+
3. Create a new feature or bugfix branch `git checkout -b feat-add-postgres18` (prefix with **feat**- or **fix**- and name it with something meaningful)
16+
4. Create a commit with a [conventional commit message](https://www.conventionalcommits.org), for example: "feat: Add Postgres 18 container" or "fix: Remove usage of deprecated PHP constant"
17+
5. Push your commits into your own repository
18+
6. Create a new Pull Request for your branch pointing to **master**.
3519

36-
We might release unstable versions. Those will be tagged on develop and released clearly marked as unstable releases.
20+
When the pull request has been approved and merged, then a release will automatically be made,
21+
using [semantic versioning](https://semver.org/) based upon the conventional commit message in the merged pull request.
22+
This will rebuild and push new versions of the containers.
3723

38-
If you have any questions don't hesitate to ask.
24+
If you have any questions don't hesitate to ask.

0 commit comments

Comments
 (0)