Skip to content

Commit 980f30b

Browse files
authored
Merge pull request #38 from hackmdio/chore/prelease
Publish pre-release(beta) build automatically
2 parents ed9db81 + 5c401ea commit 980f30b

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

.github/workflows/pre-release.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

.github/workflows/publish.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,19 @@ jobs:
3131
working-directory: nodejs
3232
run: npm publish --access public
3333
env:
34-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
34+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
35+
36+
- name: Extract version from tag
37+
run: |
38+
# Extract version from tag (remove 'v' prefix)
39+
VERSION=${GITHUB_REF#refs/tags/v}
40+
echo "VERSION=$VERSION" >> $GITHUB_ENV
41+
echo "Extracted version: $VERSION"
42+
43+
- name: Create draft release
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
run: |
47+
gh release create "$GITHUB_REF_NAME" \
48+
--title "Release v${{ env.VERSION }}" \
49+
--draft

0 commit comments

Comments
 (0)