name: CI on: push: branches: [main, develop] pull_request: branches: [main] # Required for npm Trusted Publishing (OIDC) permissions: contents: read id-token: write jobs: test: runs-on: ubuntu-latest strategy: matrix: node-version: [20.x, 22.x] steps: - uses: actions/checkout@v4 - name: Setup Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: 'npm' - name: Install dependencies run: npm ci - name: Type check run: npm run typecheck - name: Run tests run: npm test - name: Build run: npm run build publish: needs: test runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' && github.event_name == 'push' steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '22.x' registry-url: 'https://registry.npmjs.org' cache: 'npm' - name: Install dependencies run: npm ci - name: Build run: npm run build - name: Check if version changed id: version run: | CURRENT_VERSION=$(node -p "require('./package.json').version") NPM_VERSION=$(npm view opencode-puter-auth version 2>/dev/null || echo "0.0.0") if [ "$CURRENT_VERSION" != "$NPM_VERSION" ]; then echo "changed=true" >> $GITHUB_OUTPUT echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT # Check if this is a prerelease version (contains -) if [[ "$CURRENT_VERSION" == *"-"* ]]; then # Extract the prerelease tag (beta, alpha, rc, etc.) PRERELEASE_TAG=$(echo "$CURRENT_VERSION" | sed 's/.*-\([a-zA-Z]*\).*/\1/') echo "tag=$PRERELEASE_TAG" >> $GITHUB_OUTPUT else echo "tag=latest" >> $GITHUB_OUTPUT fi fi # Update npm for Trusted Publishing support (requires npm v11.5.1+) - name: Update npm to latest if: steps.version.outputs.changed == 'true' run: npm install -g npm@latest - name: Publish to npm with provenance if: steps.version.outputs.changed == 'true' run: npm publish --provenance --access public --tag ${{ steps.version.outputs.tag }}