|
| 1 | +name: Canary Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - dev |
| 7 | + paths-ignore: |
| 8 | + - "**.md" |
| 9 | + - "docs/**" |
| 10 | + - "examples/**" |
| 11 | + - ".github/**" |
| 12 | + - "!.github/workflows/canary-release.yml" |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write # Required to create releases and tags |
| 16 | + |
| 17 | +jobs: |
| 18 | + generate-version: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + canary-version: ${{ steps.version.outputs.canary-version }} |
| 22 | + base-version: ${{ steps.version.outputs.base-version }} |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Setup Node.js |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: "20" |
| 31 | + |
| 32 | + - name: Get base version |
| 33 | + id: base |
| 34 | + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT |
| 35 | + |
| 36 | + - name: Query npm for existing canary versions |
| 37 | + id: npm-versions |
| 38 | + run: | |
| 39 | + BASE_VERSION="${{ steps.base.outputs.version }}" |
| 40 | + echo "Base version: $BASE_VERSION" |
| 41 | + |
| 42 | + # Query npm for all versions and find max canary increment |
| 43 | + MAX_INCREMENT=$(node -e " |
| 44 | + const { execSync } = require('child_process'); |
| 45 | + const baseVersion = process.argv[1]; |
| 46 | + let versions = []; |
| 47 | + try { |
| 48 | + const output = execSync('npm view integrate-sdk versions --json', { encoding: 'utf-8' }); |
| 49 | + versions = JSON.parse(output); |
| 50 | + } catch (e) { |
| 51 | + versions = []; |
| 52 | + } |
| 53 | + const pattern = new RegExp('^' + baseVersion.replace(/\./g, '\\.') + '-dev\\.(\\d+)$'); |
| 54 | + const matches = versions |
| 55 | + .filter(v => pattern.test(v)) |
| 56 | + .map(v => { |
| 57 | + const match = v.match(pattern); |
| 58 | + return match ? parseInt(match[1], 10) : 0; |
| 59 | + }); |
| 60 | + const maxIncrement = matches.length > 0 ? Math.max(...matches) : -1; |
| 61 | + console.log(maxIncrement); |
| 62 | + " "$BASE_VERSION") |
| 63 | + |
| 64 | + echo "max-increment=$MAX_INCREMENT" >> $GITHUB_OUTPUT |
| 65 | +
|
| 66 | + - name: Generate canary version |
| 67 | + id: version |
| 68 | + run: | |
| 69 | + BASE_VERSION="${{ steps.base.outputs.version }}" |
| 70 | + MAX_INCREMENT="${{ steps.npm-versions.outputs.max-increment }}" |
| 71 | + |
| 72 | + # Increment the number |
| 73 | + NEXT_INCREMENT=$((MAX_INCREMENT + 1)) |
| 74 | + CANARY_VERSION="${BASE_VERSION}-dev.${NEXT_INCREMENT}" |
| 75 | + |
| 76 | + echo "base-version=$BASE_VERSION" >> $GITHUB_OUTPUT |
| 77 | + echo "canary-version=$CANARY_VERSION" >> $GITHUB_OUTPUT |
| 78 | + echo "Generated canary version: $CANARY_VERSION" |
| 79 | +
|
| 80 | + publish: |
| 81 | + needs: generate-version |
| 82 | + runs-on: ubuntu-latest |
| 83 | + steps: |
| 84 | + - name: Checkout code |
| 85 | + uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - name: Setup Bun |
| 88 | + uses: oven-sh/setup-bun@v1 |
| 89 | + with: |
| 90 | + bun-version: latest |
| 91 | + |
| 92 | + - name: Install dependencies |
| 93 | + run: bun install |
| 94 | + |
| 95 | + - name: Run tests |
| 96 | + run: bun test |
| 97 | + |
| 98 | + - name: Type check |
| 99 | + run: bun run type-check |
| 100 | + |
| 101 | + - name: Build |
| 102 | + run: bun run build |
| 103 | + |
| 104 | + - name: Update package.json version |
| 105 | + run: | |
| 106 | + CANARY_VERSION="${{ needs.generate-version.outputs.canary-version }}" |
| 107 | + # Use node to update package.json version |
| 108 | + node -e " |
| 109 | + const fs = require('fs'); |
| 110 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); |
| 111 | + pkg.version = '$CANARY_VERSION'; |
| 112 | + fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); |
| 113 | + " |
| 114 | + echo "Updated package.json version to $CANARY_VERSION" |
| 115 | +
|
| 116 | + - name: Setup Node.js (for npm publish) |
| 117 | + uses: actions/setup-node@v4 |
| 118 | + with: |
| 119 | + node-version: "20" |
| 120 | + registry-url: "https://registry.npmjs.org" |
| 121 | + |
| 122 | + - name: Publish to npm |
| 123 | + run: npm publish |
| 124 | + env: |
| 125 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 126 | + |
| 127 | + - name: Create Git Tag |
| 128 | + run: | |
| 129 | + CANARY_VERSION="${{ needs.generate-version.outputs.canary-version }}" |
| 130 | + git config user.name "github-actions[bot]" |
| 131 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 132 | + git tag -a v$CANARY_VERSION -m "Canary release v$CANARY_VERSION" |
| 133 | + git push origin v$CANARY_VERSION |
| 134 | +
|
| 135 | + - name: Create GitHub Release |
| 136 | + uses: softprops/action-gh-release@v1 |
| 137 | + with: |
| 138 | + tag_name: v${{ needs.generate-version.outputs.canary-version }} |
| 139 | + name: Canary Release v${{ needs.generate-version.outputs.canary-version }} |
| 140 | + body: | |
| 141 | + ## Canary Release v${{ needs.generate-version.outputs.canary-version }} |
| 142 | +
|
| 143 | + This is a canary release from the `dev` branch. |
| 144 | +
|
| 145 | + ### Installation |
| 146 | + ```bash |
| 147 | + bun add integrate-sdk@${{ needs.generate-version.outputs.canary-version }} |
| 148 | + ``` |
| 149 | + draft: false |
| 150 | + prerelease: true |
| 151 | + |
| 152 | + - name: Github Releases To Discord |
| 153 | + if: ${{ secrets.DISCORD_WEBHOOK_URL != '' }} |
| 154 | + uses: SethCohen/github-releases-to-discord@v1.13.1 |
| 155 | + with: |
| 156 | + webhook_url: ${{ secrets.DISCORD_WEBHOOK_URL }} |
| 157 | + color: "1316451" |
| 158 | + content: "Canary release published:" |
| 159 | + footer_title: "integrate.dev" |
| 160 | + footer_timestamp: true |
| 161 | + |
0 commit comments