|
| 1 | +name: Dev Release (main) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: dev-release-${{ github.ref }} |
| 9 | + cancel-in-progress: false |
| 10 | + |
| 11 | +jobs: |
| 12 | + compute-version: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + dev_version: ${{ steps.version.outputs.dev_version }} |
| 16 | + tag_name: ${{ steps.version.outputs.tag_name }} |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Setup Node.js |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: '20.18.1' |
| 25 | + |
| 26 | + - name: Compute dev version |
| 27 | + id: version |
| 28 | + run: | |
| 29 | + BASE_VERSION=$(node -p "require('./package.json').version") |
| 30 | + DEV_VERSION="${BASE_VERSION}-dev.${{ github.run_number }}" |
| 31 | + echo "dev_version=${DEV_VERSION}" >> "${GITHUB_OUTPUT}" |
| 32 | + echo "tag_name=v${DEV_VERSION}" >> "${GITHUB_OUTPUT}" |
| 33 | + echo "Dev version: ${DEV_VERSION}" |
| 34 | +
|
| 35 | + build-binaries: |
| 36 | + needs: compute-version |
| 37 | + strategy: |
| 38 | + fail-fast: false |
| 39 | + matrix: |
| 40 | + include: |
| 41 | + - os: ubuntu-latest |
| 42 | + target: bun-linux-x64 |
| 43 | + asset: kode-linux-x64 |
| 44 | + - os: ubuntu-latest |
| 45 | + target: bun-linux-arm64 |
| 46 | + asset: kode-linux-arm64 |
| 47 | + - os: macos-latest |
| 48 | + target: bun-darwin-x64 |
| 49 | + asset: kode-darwin-x64 |
| 50 | + - os: macos-latest |
| 51 | + target: bun-darwin-arm64 |
| 52 | + asset: kode-darwin-arm64 |
| 53 | + - os: windows-latest |
| 54 | + target: bun-windows-x64 |
| 55 | + asset: kode-win32-x64.exe |
| 56 | + runs-on: ${{ matrix.os }} |
| 57 | + env: |
| 58 | + KODE_SKIP_BINARY_DOWNLOAD: "1" |
| 59 | + steps: |
| 60 | + - name: Checkout |
| 61 | + uses: actions/checkout@v4 |
| 62 | + |
| 63 | + - name: Setup Node.js |
| 64 | + uses: actions/setup-node@v4 |
| 65 | + with: |
| 66 | + node-version: '20.18.1' |
| 67 | + |
| 68 | + - name: Setup Bun |
| 69 | + uses: oven-sh/setup-bun@v1 |
| 70 | + with: |
| 71 | + bun-version: latest |
| 72 | + |
| 73 | + - name: Install |
| 74 | + run: bun install |
| 75 | + |
| 76 | + - name: Set package.json version (dev) |
| 77 | + run: | |
| 78 | + node - <<'NODE' |
| 79 | + const fs = require('node:fs') |
| 80 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')) |
| 81 | + pkg.version = process.env.DEV_VERSION |
| 82 | + fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n') |
| 83 | + NODE |
| 84 | + env: |
| 85 | + DEV_VERSION: ${{ needs.compute-version.outputs.dev_version }} |
| 86 | + |
| 87 | + - name: Build binary |
| 88 | + run: bun build src/entrypoints/index.ts --compile --target=${{ matrix.target }} --format=esm --outfile=${{ matrix.asset }} |
| 89 | + |
| 90 | + - name: Make binary executable |
| 91 | + if: runner.os != 'Windows' |
| 92 | + run: chmod +x ${{ matrix.asset }} |
| 93 | + |
| 94 | + - name: Upload binary artifact |
| 95 | + uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: ${{ matrix.asset }} |
| 98 | + path: ${{ matrix.asset }} |
| 99 | + if-no-files-found: error |
| 100 | + |
| 101 | + publish-npm: |
| 102 | + needs: compute-version |
| 103 | + runs-on: ubuntu-latest |
| 104 | + env: |
| 105 | + KODE_SKIP_BINARY_DOWNLOAD: "1" |
| 106 | + steps: |
| 107 | + - name: Checkout |
| 108 | + uses: actions/checkout@v4 |
| 109 | + |
| 110 | + - name: Setup Node.js |
| 111 | + uses: actions/setup-node@v4 |
| 112 | + with: |
| 113 | + node-version: '20.18.1' |
| 114 | + registry-url: 'https://registry.npmjs.org' |
| 115 | + |
| 116 | + - name: Setup Bun |
| 117 | + uses: oven-sh/setup-bun@v1 |
| 118 | + with: |
| 119 | + bun-version: latest |
| 120 | + |
| 121 | + - name: Install |
| 122 | + run: bun install |
| 123 | + |
| 124 | + - name: Set package.json version (dev) |
| 125 | + run: | |
| 126 | + node - <<'NODE' |
| 127 | + const fs = require('node:fs') |
| 128 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')) |
| 129 | + pkg.version = process.env.DEV_VERSION |
| 130 | + fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n') |
| 131 | + NODE |
| 132 | + env: |
| 133 | + DEV_VERSION: ${{ needs.compute-version.outputs.dev_version }} |
| 134 | + |
| 135 | + - name: Typecheck |
| 136 | + run: bun run typecheck |
| 137 | + |
| 138 | + - name: Test |
| 139 | + run: bun test |
| 140 | + |
| 141 | + - name: Build (npm) |
| 142 | + run: bun run build:npm |
| 143 | + |
| 144 | + - name: Prepublish check |
| 145 | + run: bun run scripts/prepublish-check.js |
| 146 | + |
| 147 | + - name: Publish npm (dist-tag: dev) |
| 148 | + run: npm publish --tag dev --access public --ignore-scripts |
| 149 | + env: |
| 150 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 151 | + |
| 152 | + prerelease: |
| 153 | + needs: [compute-version, build-binaries, publish-npm] |
| 154 | + runs-on: ubuntu-latest |
| 155 | + permissions: |
| 156 | + contents: write |
| 157 | + steps: |
| 158 | + - name: Download binary artifacts |
| 159 | + uses: actions/download-artifact@v4 |
| 160 | + with: |
| 161 | + path: artifacts |
| 162 | + |
| 163 | + - name: Create checksums |
| 164 | + run: | |
| 165 | + find artifacts -type f -maxdepth 2 -print0 | sort -z | xargs -0 shasum -a 256 > checksums-sha256.txt |
| 166 | + echo "Checksums:" |
| 167 | + head -n 20 checksums-sha256.txt |
| 168 | +
|
| 169 | + - name: Create GitHub prerelease |
| 170 | + uses: softprops/action-gh-release@v2 |
| 171 | + with: |
| 172 | + tag_name: ${{ needs.compute-version.outputs.tag_name }} |
| 173 | + name: ${{ needs.compute-version.outputs.tag_name }} |
| 174 | + prerelease: true |
| 175 | + files: | |
| 176 | + artifacts/**/* |
| 177 | + checksums-sha256.txt |
0 commit comments