1- name : Build and Release
1+ name : Commit Workflow
22
33on :
44 push :
5- branches :
6- - main # Modify to your branch name
5+ branches : ['main']
76
87jobs :
98 build :
109 runs-on : ubuntu-latest
1110
11+ strategy :
12+ matrix :
13+ node-version : [18.x]
14+
15+ outputs :
16+ tag : ${{ steps.get_version.outputs.tag }}
17+ preview : ${{ steps.get_preview.outputs.preview }}
18+
1219 steps :
13- - name : Checkout code
14- uses : actions/checkout@v2
20+ - uses : actions/checkout@v3
21+
22+ - uses : actions/setup-node@v4
23+ with :
24+ node-version : ${{ matrix.node-version }}
25+
26+ - run : npm install
27+
28+ - run : |
29+ npm run lint
30+ npm run format
31+
32+ - name : Build the package
33+ run : npm run build
1534
16- - name : Setup Node.js
17- uses : actions/setup-node @v2
35+ - name : Archive project folder
36+ uses : actions/upload-artifact @v2
1837 with :
19- node-version : ' 14' # Modify to your Node.js version
38+ name : dist-folder
39+ path : ./dist
2040
21- - name : Install dependencies
22- run : npm install
41+ - id : get_version
42+ run : |
43+ version=$(node -p 'require("./package.json").version')
44+ echo "::set-output name=tag::$version"
2345
24- - name : Build TypeScript
25- run : npm run build # Modify to your build script if necessary
46+ - id : get_preview
47+ run : |
48+ preview=$(node -p 'require("./package.json").preview ? "true" : "false"')
49+ echo "::set-output name=preview::$preview"
50+
51+ publish-dev :
52+ needs : build
53+ runs-on : ubuntu-latest
54+
55+ if : needs.build.outputs.preview == 'true'
56+
57+ steps :
58+ - uses : actions/checkout@v3
59+
60+ - name : Download artifact
61+ uses : actions/download-artifact@v2
62+ with :
63+ name : dist-folder
64+ path : dist
2665
27- # Add more steps for testing, linting, etc.
66+ - run : ls
2867
29- - name : Release to GitHub
30- uses : softprops/action-gh-release@v1
68+ - name : Publish to NPM (Dev Version)
69+ run : |
70+ echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
71+ npm publish --tag=dev
72+
73+ publish-prod :
74+ needs : build
75+ runs-on : ubuntu-latest
76+
77+ if : needs.build.outputs.preview != 'true'
78+
79+ steps :
80+ - uses : actions/checkout@v3
81+
82+ - name : Download artifact
83+ uses : actions/download-artifact@v2
84+ with :
85+ name : dist-folder
86+ path : dist
87+
88+ - run : ls
89+
90+ - name : Publish to NPM (Prod Version)
91+ run : |
92+ echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
93+ npm publish
94+
95+ release :
96+ needs : build
97+ runs-on : ubuntu-latest
98+
99+ steps :
100+ - uses : actions/create-release@v1
101+ env :
102+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
31103 with :
32- files : |
33- # List files to include in the release
34- dist/*.js # Modify based on your build output
35- token : ${{ secrets.GITHUB_TOKEN }}
36- body : Release ${{ github.sha }}
104+ tag_name : v${{ needs.build.outputs.tag }}
105+ release_name : Release v${{ needs.build.outputs.tag }}
106+ body : |
107+ Release v${{ needs.build.outputs.tag }}
108+ draft : false
109+ prerelease : ${{ needs.build.outputs.preview == 'true' }}
0 commit comments