1+ name : Pre-release to NPM
2+
3+ on :
4+ push :
5+ branches :
6+ - develop
7+
8+ jobs :
9+ pre-release :
10+ runs-on : ubuntu-latest
11+ steps :
12+ - uses : actions/checkout@v4
13+ with :
14+ fetch-depth : 0
15+ token : ${{ secrets.GITHUB_TOKEN }}
16+
17+ - name : Set up Node.js
18+ uses : actions/setup-node@v4
19+ with :
20+ node-version : ' 20'
21+ registry-url : ' https://registry.npmjs.org'
22+ cache : ' npm'
23+ cache-dependency-path : nodejs/package-lock.json
24+
25+ - name : Install dependencies
26+ working-directory : nodejs
27+ run : npm ci
28+
29+ - name : Configure Git
30+ run : |
31+ git config --global user.name "github-actions[bot]"
32+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
33+
34+ - name : Generate pre-release version
35+ working-directory : nodejs
36+ run : |
37+ # Get current version from package.json
38+ CURRENT_VERSION=$(node -p "require('./package.json').version")
39+
40+ # Get short commit hash
41+ SHORT_SHA=$(git rev-parse --short HEAD)
42+
43+ # Get current timestamp
44+ TIMESTAMP=$(date +%Y%m%d%H%M%S)
45+
46+ # Create pre-release version: current-version-beta.timestamp.sha
47+ PRE_RELEASE_VERSION="${CURRENT_VERSION}-beta.${TIMESTAMP}.${SHORT_SHA}"
48+
49+ echo "Pre-release version: $PRE_RELEASE_VERSION"
50+ echo "PRE_RELEASE_VERSION=$PRE_RELEASE_VERSION" >> $GITHUB_ENV
51+
52+ # Update package.json with pre-release version
53+ npm version $PRE_RELEASE_VERSION --no-git-tag-version
54+
55+ - name : Build
56+ working-directory : nodejs
57+ run : npm run build
58+
59+ - name : Publish pre-release to NPM
60+ working-directory : nodejs
61+ run : npm publish --tag beta --access public
62+ env :
63+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
64+
65+ - name : Create GitHub pre-release
66+ env :
67+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
68+ run : |
69+ gh release create "v${{ env.PRE_RELEASE_VERSION }}" \
70+ --title "Pre-release v${{ env.PRE_RELEASE_VERSION }}" \
71+ --notes "🚀 **Pre-release from develop branch**
72+
73+ This is an automated pre-release build from the develop branch.
74+
75+ **Changes:**
76+ - Commit: ${{ github.sha }}
77+ - Branch: ${{ github.ref_name }}
78+
79+ **Installation:**
80+ \`\`\`bash
81+ npm install @hackmd/api@beta
82+ \`\`\`
83+
84+ **Note:** This is a pre-release version and may contain unstable features." \
85+ --prerelease
0 commit comments