Skip to content

Commit

Permalink
ci: automatically update version and changelog for Renovate's PRs (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradSzwarc authored Feb 22, 2023
1 parent 7a7a39c commit a24affd
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
19 changes: 19 additions & 0 deletions .github/scripts/update-changelog.js
Original file line number Diff line number Diff line change
@@ -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'));
};
38 changes: 38 additions & 0 deletions .github/workflows/dependency-update-changelog.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- 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/[email protected]
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

1 comment on commit a24affd

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.