dev snapshot #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: fork-publish | |
| run-name: "${{ inputs.bump && format('release {0}', inputs.bump) || inputs.version && format('publish {0}', inputs.version) || 'dev snapshot' }}" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: "Auto-increment from latest published version" | |
| required: false | |
| type: choice | |
| default: "" | |
| options: | |
| - "" | |
| - patch | |
| - minor | |
| - major | |
| version: | |
| description: "Exact version override (takes priority over bump)" | |
| required: false | |
| type: string | |
| channel: | |
| description: "npm dist-tag (defaults to 'latest' for releases, 'dev' for push)" | |
| required: false | |
| default: "" | |
| type: choice | |
| options: | |
| - "" | |
| - latest | |
| - dev | |
| - beta | |
| create_release: | |
| description: "Create a GitHub release with binary downloads" | |
| required: false | |
| default: false | |
| type: boolean | |
| push: | |
| branches: | |
| - dev | |
| permissions: | |
| contents: write | |
| packages: write | |
| concurrency: | |
| group: fork-publish-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: ./.github/actions/setup-bun | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: "24" | |
| registry-url: ${{ vars.NPM_REGISTRY_URL || 'https://registry.npmjs.org' }} | |
| - name: Determine version | |
| id: meta | |
| run: | | |
| SCOPE="${{ vars.NPM_SCOPE || 'ofoundation' }}" | |
| REGISTRY="${{ vars.NPM_REGISTRY_URL || 'https://registry.npmjs.org' }}" | |
| PKG="@${SCOPE}/opencode" | |
| if [ -n "${{ inputs.version }}" ]; then | |
| # Explicit version override | |
| VERSION="${{ inputs.version }}" | |
| CHANNEL="${{ inputs.channel || 'latest' }}" | |
| echo "mode=explicit" >> "$GITHUB_OUTPUT" | |
| elif [ -n "${{ inputs.bump }}" ]; then | |
| # Auto-increment from latest published version | |
| CURRENT=$(npm view "$PKG" dist-tags.latest --registry "$REGISTRY" 2>/dev/null || echo "0.0.0") | |
| echo "current published version: $CURRENT" | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" | |
| case "${{ inputs.bump }}" in | |
| major) VERSION="$((MAJOR + 1)).0.0" ;; | |
| minor) VERSION="${MAJOR}.$((MINOR + 1)).0" ;; | |
| *) VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" ;; | |
| esac | |
| CHANNEL="${{ inputs.channel || 'latest' }}" | |
| echo "mode=bump (${{ inputs.bump }}): $CURRENT -> $VERSION" >> "$GITHUB_OUTPUT" | |
| else | |
| # Push to dev — timestamp snapshot | |
| TIMESTAMP=$(date -u +%Y%m%d%H%M) | |
| VERSION="0.0.0-dev-${TIMESTAMP}" | |
| CHANNEL="dev" | |
| echo "mode=snapshot" >> "$GITHUB_OUTPUT" | |
| fi | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "channel=${CHANNEL}" >> "$GITHUB_OUTPUT" | |
| echo "--- resolved ---" | |
| echo "version: ${VERSION}" | |
| echo "channel: ${CHANNEL}" | |
| - name: Build CLI binaries for all platforms | |
| run: ./packages/opencode/script/build.ts | |
| env: | |
| OPENCODE_VERSION: ${{ steps.meta.outputs.version }} | |
| OPENCODE_CHANNEL: ${{ steps.meta.outputs.channel }} | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: opencode-cli | |
| path: packages/opencode/dist | |
| retention-days: 3 | |
| outputs: | |
| version: ${{ steps.meta.outputs.version }} | |
| channel: ${{ steps.meta.outputs.channel }} | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: ./.github/actions/setup-bun | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: "24" | |
| registry-url: ${{ vars.NPM_REGISTRY_URL || 'https://registry.npmjs.org' }} | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: opencode-cli | |
| path: packages/opencode/dist | |
| - name: Verify npm auth | |
| run: npm whoami | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - run: ./script/fork-publish.ts | |
| env: | |
| OPENCODE_VERSION: ${{ needs.build.outputs.version }} | |
| OPENCODE_CHANNEL: ${{ needs.build.outputs.channel }} | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| NPM_CONFIG_PROVENANCE: false | |
| OPENCODE_NPM_SCOPE: ${{ vars.NPM_SCOPE || 'ofoundation' }} | |
| - name: Create release archives | |
| if: inputs.create_release | |
| working-directory: packages/opencode | |
| run: | | |
| for dir in dist/opencode-*/; do | |
| [ -d "$dir" ] || continue | |
| name=$(basename "$dir") | |
| if echo "$name" | grep -q linux; then | |
| tar -czf "dist/${name}.tar.gz" -C "${dir}bin" . | |
| else | |
| ( cd "${dir}bin" && zip -r "../../${name}.zip" . ) | |
| fi | |
| done | |
| - name: Create GitHub release | |
| if: inputs.create_release | |
| run: | | |
| gh release create "v${VERSION}" \ | |
| --title "v${VERSION}" \ | |
| --generate-notes \ | |
| packages/opencode/dist/*.tar.gz \ | |
| packages/opencode/dist/*.zip | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| VERSION: ${{ needs.build.outputs.version }} |