Skip to content

Build and Release

Build and Release #20

Workflow file for this run

name: Build and Release
on:
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Get latest release version from PMHQ.Rust
id: get_version
run: |
RELEASE_INFO=$(curl -s -H "Authorization: token ${{ secrets.ACTION_TOKEN }}" \
"https://api.github.com/repos/linyuchen/PMHQ.Rust/releases?per_page=1")
VERSION=$(echo "$RELEASE_INFO" | jq -r '.[0].tag_name')
RELEASE_ID=$(echo "$RELEASE_INFO" | jq -r '.[0].id')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT
NPM_VERSION=${VERSION#v}
echo "npm_version=$NPM_VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION, release_id: $RELEASE_ID"
- name: Download artifacts from PMHQ.Rust
run: |
mkdir -p artifacts
VERSION="${{ steps.get_version.outputs.version }}"
RELEASE_ID="${{ steps.get_version.outputs.release_id }}"
echo "Downloading version: $VERSION (release_id: $RELEASE_ID)"
ASSETS=$(curl -s -H "Authorization: token ${{ secrets.ACTION_TOKEN }}" \
"https://api.github.com/repos/linyuchen/PMHQ.Rust/releases/$RELEASE_ID/assets")
WIN_X64_ID=$(echo "$ASSETS" | jq -r '.[] | select(.name=="pmhq-win-x64.zip") | .id')
LINUX_X64_ID=$(echo "$ASSETS" | jq -r '.[] | select(.name=="pmhq-linux-x64.zip") | .id')
LINUX_ARM64_ID=$(echo "$ASSETS" | jq -r '.[] | select(.name=="pmhq-linux-arm64.zip") | .id')
MACOS_ARM64_ID=$(echo "$ASSETS" | jq -r '.[] | select(.name=="pmhq-darwin-arm64.zip") | .id')
echo "Asset IDs: win-x64=$WIN_X64_ID, linux-x64=$LINUX_X64_ID, linux-arm64=$LINUX_ARM64_ID"
curl -fL -H "Authorization: token ${{ secrets.ACTION_TOKEN }}" \
-H "Accept: application/octet-stream" \
-o artifacts/pmhq-win-x64.zip \
"https://api.github.com/repos/linyuchen/PMHQ.Rust/releases/assets/$WIN_X64_ID"
curl -fL -H "Authorization: token ${{ secrets.ACTION_TOKEN }}" \
-H "Accept: application/octet-stream" \
-o artifacts/pmhq-linux-x64.zip \
"https://api.github.com/repos/linyuchen/PMHQ.Rust/releases/assets/$LINUX_X64_ID"
curl -fL -H "Authorization: token ${{ secrets.ACTION_TOKEN }}" \
-H "Accept: application/octet-stream" \
-o artifacts/pmhq-linux-arm64.zip \
"https://api.github.com/repos/linyuchen/PMHQ.Rust/releases/assets/$LINUX_ARM64_ID"
curl -fL -H "Authorization: token ${{ secrets.ACTION_TOKEN }}" \
-H "Accept: application/octet-stream" \
-o artifacts/pmhq-macos-arm64.zip \
"https://api.github.com/repos/linyuchen/PMHQ.Rust/releases/assets/$MACOS_ARM64_ID"
ls -la artifacts/
- name: Create Release Draft
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.get_version.outputs.version }}
name: Release ${{ steps.get_version.outputs.version }}
draft: true
files: |
artifacts/pmhq-win-x64.zip
artifacts/pmhq-linux-x64.zip
artifacts/pmhq-linux-arm64.zip
artifacts/pmhq-macos-arm64.zip
env:
GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Publish pmhq-dist-win-x64
continue-on-error: true
run: |
npm install -g npm@latest
mkdir -p package-win-x64
unzip -j artifacts/pmhq-win-x64.zip -d package-win-x64
echo '{"name": "pmhq-dist-win-x64", "version": "${{ steps.get_version.outputs.npm_version }}", "author": "linyuchen", "repository": {"type": "git", "url": "https://github.com/linyuchen/PMHQ"}}' > package-win-x64/package.json
cd package-win-x64
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish pmhq-dist-linux-x64
continue-on-error: true
run: |
mkdir -p package-linux-x64
unzip -j artifacts/pmhq-linux-x64.zip -d package-linux-x64
echo '{"name": "pmhq-dist-linux-x64", "version": "${{ steps.get_version.outputs.npm_version }}", "author": "linyuchen", "repository": {"type": "git", "url": "https://github.com/linyuchen/PMHQ"}}' > package-linux-x64/package.json
cd package-linux-x64
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish pmhq-dist-linux-arm64
continue-on-error: true
run: |
mkdir -p package-linux-arm64
unzip -j artifacts/pmhq-linux-arm64.zip -d package-linux-arm64
echo '{"name": "pmhq-dist-linux-arm64", "version": "${{ steps.get_version.outputs.npm_version }}", "author": "linyuchen", "repository": {"type": "git", "url": "https://github.com/linyuchen/PMHQ"}}' > package-linux-arm64/package.json
cd package-linux-arm64
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}