ci: automatically update version and changelog for Renovate's PRs (#206)

This commit is contained in:
Konrad Szwarc 2023-02-22 20:46:11 +01:00 committed by GitHub
parent 7a7a39c67d
commit a24affd6bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 3 deletions

19
.github/scripts/update-changelog.js vendored Normal file
View file

@ -0,0 +1,19 @@
const fs = require('fs');
module.exports = (version, prUrl) => {
const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
const changelogLines = changelog.split('\n');
const lastChangeIndex = changelogLines.findIndex((line) => line.startsWith('## ['));
const textToAppend = `
## [${version}] - ${new Date().toISOString().split('T')[0]}
### Dependencies
- chore(deps): update dependencies ([details](${prUrl}))
`.trim();
changelogLines.splice(lastChangeIndex, 0, textToAppend + '\n');
fs.writeFileSync('CHANGELOG.md', changelogLines.join('\n'));
};

View file

@ -0,0 +1,38 @@
name: Modify changelog for dependency updates
on:
pull_request:
types: [labeled]
jobs:
build:
if: github.event.label.name == 'dependencies' && github.repository == 'KonradSzwarc/devscard'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Get project information
id: projectinfo
uses: gregoranders/nodejs-project-info@v0.0.19
- name: Get next possible versions
id: semvers
uses: WyriHaximus/github-action-next-semvers@v1
with:
version: ${{ steps.projectinfo.outputs.version }}
- name: Update package.json version
uses: reedyuk/npm-version@1.1.1
with:
version: ${{ steps.semvers.outputs.patch }}
- name: Update CHANGELOG.md
uses: actions/github-script@v6
with:
script: |
const script = require('.github/scripts/update-changelog.js');
const version = '${{ steps.semvers.outputs.patch }}';
const prUrl = '${{ github.event.pull_request.url }}';
script(version, prUrl);
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4

View file

@ -2,12 +2,22 @@
All notable changes to this project will be documented in this file.
## [0.0.4] - 2023-02-22
### Workflow
- ci: automatically update project version and changelog for Renovate's PRs
## [0.0.3] - 2023-02-21
### Dependencies
- chore(deps): update dependencies ([details](https://github.com/KonradSzwarc/devscard/pull/202))
## [0.0.2] - 2023-02-16
### Dependencies
- chore(deps): update dependencies ([details](https://github.com/KonradSzwarc/devscard/pull/201))
## [0.0.1] - 2023-02-08

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "devscard",
"version": "0.0.2",
"version": "0.0.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "devscard",
"version": "0.0.2",
"version": "0.0.4",
"hasInstallScript": true,
"dependencies": {
"@floating-ui/dom": "1.2.1",

View file

@ -1,7 +1,7 @@
{
"name": "devscard",
"description": "Template for creating a comprehensive virtual CV for developers.",
"version": "0.0.3",
"version": "0.0.4",
"private": true,
"engines": {
"node": ">=14",