|
| 1 | +name: Generate Changelog |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # pull_request: |
| 6 | + # types: |
| 7 | + # - closed |
| 8 | + branches: |
| 9 | + - changelong-generation |
| 10 | + paths-ignore: |
| 11 | + - 'docs/changelog/changelog.mdx' # Prevent recursive triggers |
| 12 | + |
| 13 | +jobs: |
| 14 | + generate-changelog: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + # if: github.event.pull_request.merged == true |
| 17 | + permissions: |
| 18 | + contents: write |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 # Important: This fetches all history for all branches and tags |
| 23 | + |
| 24 | + - name: Setup Node.js |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: '20' |
| 28 | + |
| 29 | + - name: Install conventional-changelog-cli |
| 30 | + run: npm install -g conventional-changelog-cli |
| 31 | + |
| 32 | + - name: Generate Changelog |
| 33 | + run: | |
| 34 | + # Ensure the changelog directory exists |
| 35 | + mkdir -p docs/changelog |
| 36 | +
|
| 37 | + # Create or update the frontmatter if file doesn't exist |
| 38 | + if [ ! -f docs/changelog/changelog.mdx ]; then |
| 39 | + echo "---" > docs/changelog/changelog.mdx |
| 40 | + echo "title: 'Changelog'" >> docs/changelog/changelog.mdx |
| 41 | + echo "description: 'Track all notable changes to our project'" >> docs/changelog/changelog.mdx |
| 42 | + echo "---" >> docs/changelog/changelog.mdx |
| 43 | + echo "" >> docs/changelog/changelog.mdx |
| 44 | + echo "# Changelog" >> docs/changelog/changelog.mdx |
| 45 | + echo "" >> docs/changelog/changelog.mdx |
| 46 | + fi |
| 47 | +
|
| 48 | + # Generate the changelog |
| 49 | + conventional-changelog -p angular -i docs/changelog/changelog.mdx -s |
| 50 | +
|
| 51 | + - name: Commit and push if changed |
| 52 | + run: | |
| 53 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 54 | + git config --global user.name "GitHub Actions" |
| 55 | + git add docs/changelog/changelog.mdx |
| 56 | +
|
| 57 | + # Only commit and push if there are changes |
| 58 | + if git diff --staged --quiet; then |
| 59 | + echo "No changes to commit" |
| 60 | + else |
| 61 | + git commit -m "docs(changelog): update changelog [skip ci]" |
| 62 | + git push |
| 63 | + fi |
0 commit comments