|
| 1 | +name: sdk-gitpkg |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - dev |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + gitpkg: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - uses: ./.github/actions/setup-bun |
| 20 | + |
| 21 | + - uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: "24" |
| 24 | + |
| 25 | + - name: Read metadata |
| 26 | + id: meta |
| 27 | + run: | |
| 28 | + VERSION=$(node -p "require('./packages/sdk/js/package.json').version") |
| 29 | + SHA=$(git rev-parse --short HEAD) |
| 30 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 31 | + echo "sha=$SHA" >> $GITHUB_OUTPUT |
| 32 | +
|
| 33 | + - name: Check release |
| 34 | + env: |
| 35 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + run: | |
| 37 | + TAG="@opencode-ai/sdk-${{ steps.meta.outputs.version }}-gitpkg" |
| 38 | + if gh release view "$TAG" >/dev/null 2>&1; then |
| 39 | + echo "Release already exists: $TAG" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + if git ls-remote --tags origin "refs/tags/$TAG" | grep -q .; then |
| 43 | + echo "Tag already exists: $TAG" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Build sdk |
| 48 | + run: bun run --cwd packages/sdk/js build |
| 49 | + |
| 50 | + - name: Prepare gitpkg exports |
| 51 | + run: bun ./packages/sdk/js/script/gitpkg.ts |
| 52 | + |
| 53 | + - name: Pack sdk |
| 54 | + working-directory: packages/sdk/js |
| 55 | + run: bun pm pack |
| 56 | + |
| 57 | + - name: Rename tarball |
| 58 | + id: pack |
| 59 | + working-directory: packages/sdk/js |
| 60 | + run: | |
| 61 | + FILE=$(ls opencode-ai-sdk-*.tgz) |
| 62 | + NAME="opencode-ai-sdk-${{ steps.meta.outputs.version }}-gitpkg-${{ steps.meta.outputs.sha }}.tgz" |
| 63 | + mv "$FILE" "$NAME" |
| 64 | + echo "tarball=$NAME" >> $GITHUB_OUTPUT |
| 65 | +
|
| 66 | + - name: Commit gitpkg |
| 67 | + run: | |
| 68 | + git config user.email "github-actions@users.noreply.github.com" |
| 69 | + git config user.name "github-actions" |
| 70 | + git add -f packages/sdk/js/dist |
| 71 | + git add packages/sdk/js/package.json |
| 72 | + git commit -m "chore: prepare sdk gitpkg ${{ steps.meta.outputs.version }}" |
| 73 | +
|
| 74 | + - name: Create root tag commit |
| 75 | + run: | |
| 76 | + git subtree split --prefix=packages/sdk/js -b sdk-gitpkg-root |
| 77 | +
|
| 78 | + - name: Tag gitpkg |
| 79 | + run: | |
| 80 | + TAG="@opencode-ai/sdk-${{ steps.meta.outputs.version }}-gitpkg" |
| 81 | + git tag "$TAG" sdk-gitpkg-root |
| 82 | + git push origin "$TAG" |
| 83 | +
|
| 84 | + - name: Create release |
| 85 | + env: |
| 86 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + run: | |
| 88 | + TAG="@opencode-ai/sdk-${{ steps.meta.outputs.version }}-gitpkg" |
| 89 | + FILE="packages/sdk/js/${{ steps.pack.outputs.tarball }}" |
| 90 | + gh release create "$TAG" "$FILE" --title "$TAG" --notes "Commit: ${{ steps.meta.outputs.sha }}" |
0 commit comments