1+ name : Publish Package
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ package :
7+ description : ' Package to publish'
8+ required : true
9+ type : choice
10+ options :
11+ - core
12+ - react
13+ version :
14+ description : ' Version to publish (e.g., 1.0.0 for release, 1.0.0-beta.1 for prerelease)'
15+ required : true
16+ type : string
17+ prerelease :
18+ description : ' Is this a prerelease?'
19+ required : false
20+ type : boolean
21+ default : false
22+
23+ jobs :
24+ publish :
25+ runs-on : ubuntu-latest
26+ permissions :
27+ contents : write
28+ packages : write
29+
30+ steps :
31+ - name : Checkout repository
32+ uses : actions/checkout@v4
33+ with :
34+ token : ${{ secrets.PACKAGE_KEY }}
35+
36+ - name : Setup Node.js
37+ uses : actions/setup-node@v4
38+ with :
39+ node-version : ' 18'
40+ registry-url : ' https://npm.pkg.github.com'
41+ scope : ' @context-query'
42+
43+ - name : Install pnpm
44+ uses : pnpm/action-setup@v2
45+ with :
46+ version : 9.0.0
47+
48+ - name : Install dependencies
49+ run : pnpm install --no-frozen-lockfile
50+
51+ - name : Validate version format
52+ run : |
53+ VERSION="${{ github.event.inputs.version }}"
54+ IS_PRERELEASE="${{ github.event.inputs.prerelease }}"
55+
56+ # Check if version matches prerelease setting
57+ if [[ "$IS_PRERELEASE" == "true" ]]; then
58+ if ! [[ "$VERSION" =~ -([a-zA-Z]+)\.?[0-9]* ]]; then
59+ echo "Error: Prerelease version must include a prerelease identifier (e.g., 1.0.0-beta.1, 1.0.0-alpha.1, 1.0.0-rc.1)"
60+ exit 1
61+ fi
62+ echo "Valid prerelease version: $VERSION"
63+ else
64+ if [[ "$VERSION" =~ - ]]; then
65+ echo "Error: Release version should not contain prerelease identifiers. Use format like 1.0.0"
66+ exit 1
67+ fi
68+ echo "Valid release version: $VERSION"
69+ fi
70+
71+ - name : Update package version
72+ run : |
73+ cd packages/${{ github.event.inputs.package }}
74+ npm version ${{ github.event.inputs.version }} --no-git-tag-version
75+ echo "Updated version to ${{ github.event.inputs.version }}"
76+
77+ - name : Build package
78+ run : |
79+ cd packages/${{ github.event.inputs.package }}
80+ pnpm run build
81+
82+ - name : Configure npm authentication
83+ run : |
84+ echo "@context-query:registry=https://npm.pkg.github.com" >> ~/.npmrc
85+ echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGE_KEY }}" >> ~/.npmrc
86+
87+ - name : Publish to GitHub Packages
88+ run : |
89+ cd packages/${{ github.event.inputs.package }}
90+ if [[ "${{ github.event.inputs.prerelease }}" == "true" ]]; then
91+ npm publish --tag prerelease
92+ echo "Published as prerelease with tag 'prerelease'"
93+ else
94+ npm publish
95+ echo "Published as latest"
96+ fi
97+ env :
98+ NODE_AUTH_TOKEN : ${{ secrets.PACKAGE_KEY }}
99+
100+ - name : Commit version change
101+ if : github.event.inputs.prerelease == 'false'
102+ run : |
103+ git config --global user.name "GitHub Actions"
104+ git config --global user.email "actions@github.com"
105+ git add packages/${{ github.event.inputs.package }}/package.json
106+ git commit -m "chore: bump @context-query/${{ github.event.inputs.package }} to v${{ github.event.inputs.version }}"
107+ git push
108+
109+ - name : Create Git tag
110+ if : github.event.inputs.prerelease == 'false'
111+ run : |
112+ TAG_NAME="${{ github.event.inputs.package }}-v${{ github.event.inputs.version }}"
113+ git tag $TAG_NAME
114+ git push origin $TAG_NAME
115+ echo "Created tag: $TAG_NAME"
116+
117+ - name : Create GitHub Release
118+ if : github.event.inputs.prerelease == 'false'
119+ uses : actions/create-release@v1
120+ env :
121+ GITHUB_TOKEN : ${{ secrets.PACKAGE_KEY }}
122+ with :
123+ tag_name : ${{ github.event.inputs.package }}-v${{ github.event.inputs.version }}
124+ release_name : " @context-query/${{ github.event.inputs.package }} v${{ github.event.inputs.version }}"
125+ body : |
126+ ## @context-query/${{ github.event.inputs.package }} v${{ github.event.inputs.version }}
127+
128+ Published to GitHub Packages.
129+
130+ ### Installation
131+ ```bash
132+ # Install specific version
133+ npm install @context-query/${{ github.event.inputs.package }}@${{ github.event.inputs.version }}
134+
135+ # Install latest stable version
136+ npm install @context-query/${{ github.event.inputs.package }}@latest
137+ ```
138+ draft : false
139+ prerelease : false
0 commit comments