diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 0000000..de60d8b --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bc8e584..d0cbd90 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,4 +31,19 @@ jobs: working-directory: nodejs run: npm publish --access public env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file + 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 \ No newline at end of file