Skip to content

Publish pre-release(beta) build automatically #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Pre-release to NPM

on:
push:
branches:
- develop

jobs:
pre-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: nodejs/package-lock.json

- name: Install dependencies
working-directory: nodejs
run: npm ci

- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Generate pre-release version
working-directory: nodejs
run: |
# Get current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")

# Get short commit hash
SHORT_SHA=$(git rev-parse --short HEAD)

# Get current timestamp
TIMESTAMP=$(date +%Y%m%d%H%M%S)

# Create pre-release version: current-version-beta.timestamp.sha
PRE_RELEASE_VERSION="${CURRENT_VERSION}-beta.${TIMESTAMP}.${SHORT_SHA}"

echo "Pre-release version: $PRE_RELEASE_VERSION"
echo "PRE_RELEASE_VERSION=$PRE_RELEASE_VERSION" >> $GITHUB_ENV

# Update package.json with pre-release version
npm version $PRE_RELEASE_VERSION --no-git-tag-version

- name: Build
working-directory: nodejs
run: npm run build

- name: Publish pre-release to NPM
working-directory: nodejs
run: npm publish --tag beta --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create GitHub pre-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "v${{ env.PRE_RELEASE_VERSION }}" \
--title "Pre-release v${{ env.PRE_RELEASE_VERSION }}" \
--notes "🚀 **Pre-release from develop branch**

This is an automated pre-release build from the develop branch.

**Changes:**
- Commit: ${{ github.sha }}
- Branch: ${{ github.ref_name }}

**Installation:**
\`\`\`bash
npm install @hackmd/api@beta
\`\`\`

**Note:** This is a pre-release version and may contain unstable features." \
--prerelease
17 changes: 16 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ jobs:
working-directory: nodejs
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Extract version from tag
run: |
# Extract version from tag (remove 'v' prefix)
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Extracted version: $VERSION"

- name: Create draft release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "$GITHUB_REF_NAME" \
--title "Release v${{ env.VERSION }}" \
--draft