Skip to content

Commit 1fa6874

Browse files
authored
Merge pull request #47 from palashmon/feat/npm-publish
feat: update npm-publish gh action
2 parents c77ba45 + 85a8f4e commit 1fa6874

File tree

1 file changed

+93
-3
lines changed

1 file changed

+93
-3
lines changed

.github/workflows/npm-publish.yml

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
name: Publish Package to npmjs
2+
23
on:
3-
release:
4-
types: [published]
4+
workflow_run:
5+
workflows: [CI]
6+
branches: [master]
7+
types: [completed]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
contents: write
15+
packages: write
16+
pull-requests: write
17+
518
jobs:
619
build:
720
runs-on: ubuntu-latest
@@ -13,8 +26,85 @@ jobs:
1326
- run: npm i
1427
- run: npm test
1528

29+
changelog:
30+
name: Changelog
31+
needs:
32+
- build
33+
if: github.event_name != 'pull_request'
34+
runs-on: ubuntu-latest
35+
36+
outputs:
37+
skipped: ${{ steps.changelog.outputs.skipped }}
38+
tag: ${{ steps.changelog.outputs.tag }}
39+
clean_changelog: ${{ steps.changelog.outputs.clean_changelog }}
40+
version: ${{ steps.changelog.outputs.version }}
41+
42+
env:
43+
PR_BRANCH: release/ci-${{ github.sha }}
44+
45+
steps:
46+
- name: Checkout branch
47+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
48+
with:
49+
fetch-depth: '0'
50+
51+
- name: Create release branch
52+
run: |
53+
git checkout -b ${{ env.PR_BRANCH }}
54+
55+
- name: Create Changelog
56+
id: changelog
57+
uses: TriPSs/conventional-changelog-action@dd19d7c07e5f620b2d6f48d547148a4b6b29e92f # v3.19.0
58+
with:
59+
github-token: ${{ secrets.GITHUB_TOKEN }}
60+
git-user-name: "github-actions"
61+
git-user-email: "github-actions[bot]@users.noreply.github.com"
62+
git-branch: ${{ env.PR_BRANCH }}
63+
skip-git-pull: true
64+
output-file: false
65+
create-summary: true
66+
skip-on-empty: false
67+
release-count: 10
68+
69+
# create PR using GitHub CLI
70+
- name: Create Changelog PR
71+
if: steps.changelog.outputs.skipped == 'false'
72+
run: |
73+
gh pr create --base master --head ${{ env.PR_BRANCH }} --title 'chore(release): ${{ steps.changelog.outputs.tag }} [skip-ci]' --body '${{ steps.changelog.outputs.clean_changelog }}'
74+
env:
75+
GH_TOKEN: ${{ github.token }}
76+
77+
- name: Merge Changelog PR
78+
if: steps.changelog.outputs.skipped == 'false'
79+
run: |
80+
gh pr merge --squash --auto --delete-branch ${{ env.PR_BRANCH }}
81+
env:
82+
GH_TOKEN: ${{ github.token }}
83+
84+
release:
85+
name: GitHub Release
86+
needs: changelog
87+
if: github.event_name != 'pull_request' && needs.changelog.outputs.skipped == 'false'
88+
runs-on: ubuntu-latest
89+
steps:
90+
- name: Checkout
91+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
92+
93+
- name: Create Release
94+
uses: softprops/action-gh-release@v2
95+
with:
96+
token: ${{ secrets.GITHUB_TOKEN }}
97+
name: ${{ needs.changelog.outputs.tag }}
98+
tag_name: ${{ needs.changelog.outputs.tag }}
99+
draft: false
100+
generate_release_notes: true
101+
make_latest: 'true'
102+
prerelease: false
103+
16104
publish-npm:
17-
needs: build
105+
name: NPM Release
106+
needs: changelog
107+
if: github.event_name != 'pull_request' && needs.changelog.outputs.skipped == 'false'
18108
runs-on: ubuntu-latest
19109
steps:
20110
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

0 commit comments

Comments
 (0)