name: Publish to npm
on:
workflow_dispatch:
permissions:
contents: write
id-token: write
jobs:
get-version:
name: Get version from Cargo.toml
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v6
- name: Extract version from Cargo.toml
id: version
run: |
VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "//;s/"//' | tr -d ' ')
echo "version=$VERSION" >> $GITHUB_OUTPUT
publish-platforms:
name: Publish platform packages
runs-on: ubuntu-latest
needs: get-version
strategy:
fail-fast: false
matrix:
platform:
- linux-x64
- linux-arm64
- darwin-x64
- darwin-arm64
- win32-x64
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Download release assets for version
run: |
TAG="v${{ needs.get-version.outputs.version }}"
gh release view "$TAG" --repo repohelper/codexctl >/dev/null
gh release download "$TAG" --repo repohelper/codexctl --dir artifacts
ls -la artifacts/
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract binary
run: |
mkdir -p npm-platforms/${{ matrix.platform }}/bin
case "${{ matrix.platform }}" in
linux-x64)
tar -xzf artifacts/codexctl-x86_64-unknown-linux-gnu.tar.gz -C npm-platforms/${{ matrix.platform }}/bin
;;
linux-arm64)
tar -xzf artifacts/codexctl-aarch64-unknown-linux-gnu.tar.gz -C npm-platforms/${{ matrix.platform }}/bin
;;
darwin-x64)
tar -xzf artifacts/codexctl-x86_64-apple-darwin.tar.gz -C npm-platforms/${{ matrix.platform }}/bin
;;
darwin-arm64)
tar -xzf artifacts/codexctl-aarch64-apple-darwin.tar.gz -C npm-platforms/${{ matrix.platform }}/bin
;;
win32-x64)
unzip -o artifacts/codexctl-x86_64-pc-windows-msvc.zip -d npm-platforms/${{ matrix.platform }}/bin
;;
esac
ls -la npm-platforms/${{ matrix.platform }}/bin/
- name: Update version
run: |
sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"${{ needs.get-version.outputs.version }}\"/" npm-platforms/${{ matrix.platform }}/package.json
cat npm-platforms/${{ matrix.platform }}/package.json
- name: Publish to npm
run: |
cd npm-platforms/${{ matrix.platform }}
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-main:
name: Publish main package
runs-on: ubuntu-latest
needs: [get-version]
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Update version
working-directory: ./npm
run: |
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.version = '${{ needs.get-version.outputs.version }}';
for (const key of Object.keys(pkg.optionalDependencies)) {
pkg.optionalDependencies[key] = '^${{ needs.get-version.outputs.version }}';
}
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
cat package.json
- name: Publish to npm
working-directory: ./npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-success:
name: Notify completion
runs-on: ubuntu-latest
needs: [publish-platforms, publish-main]
if: always()
steps:
- run: |
echo "Publishing completed"
echo "Platform packages: ${{ needs.publish-platforms.result }}"
echo "Main package: ${{ needs.publish-main.result }}"