Skip to content

Commit 5e0a380

Browse files
committed
Add github workflow to publish and release package
[skip ci]
1 parent c482200 commit 5e0a380

File tree

2 files changed

+148
-1
lines changed

2 files changed

+148
-1
lines changed

.github/workflows/publish-release.yml

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Publish & Release
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
build:
7+
name: Build
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
13+
- name: Setup node
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: 20
17+
cache: yarn
18+
env:
19+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
20+
21+
- name: Install dependencies
22+
run: |
23+
yarn config set network-timeout 300000
24+
yarn install --prefer-offline
25+
env:
26+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27+
28+
- name: Build
29+
continue-on-error: false
30+
run: yarn build
31+
env:
32+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
33+
34+
- name: Upload artifact
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: dist
38+
path: dist
39+
retention-days: 30
40+
41+
push:
42+
name: Push
43+
needs: build
44+
runs-on: ubuntu-latest
45+
permissions:
46+
contents: write
47+
env:
48+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v4
52+
53+
- name: Download artifact
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: dist
57+
path: dist
58+
59+
- name: Push distribution
60+
run: |
61+
MSG="$(printf "Publish distribution\n[skip ci]")"
62+
git config --global user.name "github-actions[bot]"
63+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
64+
git add dist/index.min.* -f
65+
git diff-index --quiet HEAD || git commit -m "$MSG" --no-verify --signoff
66+
git push origin $BRANCH_NAME
67+
68+
deploy:
69+
name: Deploy
70+
needs: build
71+
runs-on: ubuntu-latest
72+
permissions:
73+
id-token: write
74+
contents: read
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@v4
78+
79+
- name: Download artifact
80+
uses: actions/download-artifact@v4
81+
with:
82+
name: dist
83+
path: dist
84+
85+
- name: Configure AWS credentials
86+
uses: aws-actions/configure-aws-credentials@v4
87+
with:
88+
role-to-assume: ${{ secrets.AWS_GITHUB_ACTION_ROLE }}
89+
aws-region: us-east-2
90+
91+
- name: Sync files to S3 bucket
92+
run: |
93+
PACKAGE_VERSION=$(npm pkg get version --workspaces=false | tr -d \")
94+
aws s3 sync dist s3://cdn.zigurous.com/forge-react@$PACKAGE_VERSION/dist --delete --exclude "*.ts"
95+
96+
publish:
97+
name: Publish
98+
needs: [push, deploy]
99+
runs-on: ubuntu-latest
100+
steps:
101+
- name: Checkout
102+
uses: actions/checkout@v4
103+
104+
- name: Download artifact
105+
uses: actions/download-artifact@v4
106+
with:
107+
name: dist
108+
path: dist
109+
110+
- name: Setup node
111+
uses: actions/setup-node@v4
112+
with:
113+
node-version: 20
114+
cache: yarn
115+
env:
116+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
117+
118+
- name: Install dependencies
119+
run: |
120+
yarn config set network-timeout 300000
121+
yarn install --prefer-offline
122+
env:
123+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
124+
125+
- name: Publish to NPM
126+
run: |
127+
npm publish
128+
env:
129+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
130+
131+
release:
132+
name: Release
133+
needs: publish
134+
runs-on: ubuntu-latest
135+
steps:
136+
- name: Checkout
137+
uses: actions/checkout@v4
138+
139+
- name: Create release
140+
env:
141+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142+
run: |
143+
PACKAGE_VERSION=$(npm pkg get version --workspaces=false | tr -d \")
144+
gh release create "$PACKAGE_VERSION" \
145+
--target ${{ github.ref_name }} \
146+
--title "$PACKAGE_VERSION" \
147+
--latest

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Forge React
22

3-
<a href="https://github.com/zigurous/forge-react/actions"><img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/zigurous/forge-react/build-push-deploy.yml" /></a>
3+
<a href="https://github.com/zigurous/forge-react/actions"><img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/zigurous/forge-react/publish-release.yml" /></a>
44
<a href="https://github.com/zigurous/forge-react/pkgs/npm/forge-react"><img alt="GitHub package.json version" src="https://img.shields.io/github/package-json/v/zigurous/forge-react" /></a>
55
<a href="https://github.com/zigurous/forge-react/blob/main/LICENSE"><img alt="GitHub License" src="https://img.shields.io/github/license/zigurous/forge-react" /></a>
66

0 commit comments

Comments
 (0)