|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + id-token: write |
| 11 | + |
| 12 | +env: |
| 13 | + GH_REPO: AltimateAI/altimate-code |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - uses: oven-sh/setup-bun@v2 |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + run: bun install |
| 26 | + |
| 27 | + - name: Build all targets |
| 28 | + run: bun run packages/altimate-code/script/build.ts |
| 29 | + env: |
| 30 | + ALTIMATE_CLI_VERSION: ${{ github.ref_name }} |
| 31 | + ALTIMATE_CLI_CHANNEL: latest |
| 32 | + ALTIMATE_CLI_RELEASE: "1" |
| 33 | + GH_REPO: ${{ env.GH_REPO }} |
| 34 | + MODELS_DEV_API_JSON: packages/altimate-code/test/tool/fixtures/models-api.json |
| 35 | + |
| 36 | + - name: Upload build artifacts |
| 37 | + uses: actions/upload-artifact@v4 |
| 38 | + with: |
| 39 | + name: dist |
| 40 | + path: packages/altimate-code/dist/ |
| 41 | + |
| 42 | + publish-npm: |
| 43 | + name: Publish to npm |
| 44 | + needs: build |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - uses: oven-sh/setup-bun@v2 |
| 50 | + |
| 51 | + - name: Install dependencies |
| 52 | + run: bun install |
| 53 | + |
| 54 | + - name: Download build artifacts |
| 55 | + uses: actions/download-artifact@v4 |
| 56 | + with: |
| 57 | + name: dist |
| 58 | + path: packages/altimate-code/dist/ |
| 59 | + |
| 60 | + - name: Publish to npm |
| 61 | + run: bun run packages/altimate-code/script/publish.ts |
| 62 | + env: |
| 63 | + ALTIMATE_CLI_VERSION: ${{ github.ref_name }} |
| 64 | + ALTIMATE_CLI_CHANNEL: latest |
| 65 | + ALTIMATE_CLI_RELEASE: "1" |
| 66 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 67 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 68 | + GH_REPO: ${{ env.GH_REPO }} |
| 69 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + |
| 71 | + publish-engine: |
| 72 | + name: Publish engine to PyPI |
| 73 | + needs: build |
| 74 | + runs-on: ubuntu-latest |
| 75 | + environment: pypi |
| 76 | + permissions: |
| 77 | + id-token: write |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - uses: actions/setup-python@v5 |
| 82 | + with: |
| 83 | + python-version: "3.12" |
| 84 | + |
| 85 | + - name: Install build tools |
| 86 | + run: pip install build |
| 87 | + |
| 88 | + - name: Build package |
| 89 | + run: python -m build |
| 90 | + working-directory: packages/altimate-engine |
| 91 | + |
| 92 | + - name: Publish to PyPI |
| 93 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 94 | + with: |
| 95 | + packages-dir: packages/altimate-engine/dist/ |
| 96 | + |
| 97 | + github-release: |
| 98 | + name: Create GitHub Release |
| 99 | + needs: [build, publish-npm] |
| 100 | + runs-on: ubuntu-latest |
| 101 | + permissions: |
| 102 | + contents: write |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + with: |
| 106 | + fetch-depth: 0 |
| 107 | + |
| 108 | + - name: Generate release notes |
| 109 | + id: notes |
| 110 | + run: | |
| 111 | + # Validate tag format to prevent injection |
| 112 | + if ! echo "$CURRENT_TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9._-]+)?$'; then |
| 113 | + echo "::error::Invalid tag format: $CURRENT_TAG" |
| 114 | + exit 1 |
| 115 | + fi |
| 116 | +
|
| 117 | + # Get the previous tag |
| 118 | + PREV_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]' | head -2 | tail -1) |
| 119 | +
|
| 120 | + # Generate changelog from commits between tags |
| 121 | + echo "## What's Changed" > notes.md |
| 122 | + echo "" >> notes.md |
| 123 | +
|
| 124 | + if [ -n "$PREV_TAG" ]; then |
| 125 | + # Categorize commits |
| 126 | + echo "### Features" >> notes.md |
| 127 | + git log "${PREV_TAG}".."${CURRENT_TAG}" --pretty=format:"- %s (%h)" --grep="^feat" >> notes.md || true |
| 128 | + echo "" >> notes.md |
| 129 | + echo "" >> notes.md |
| 130 | +
|
| 131 | + echo "### Bug Fixes" >> notes.md |
| 132 | + git log "${PREV_TAG}".."${CURRENT_TAG}" --pretty=format:"- %s (%h)" --grep="^fix" >> notes.md || true |
| 133 | + echo "" >> notes.md |
| 134 | + echo "" >> notes.md |
| 135 | +
|
| 136 | + echo "### Other Changes" >> notes.md |
| 137 | + git log "${PREV_TAG}".."${CURRENT_TAG}" --pretty=format:"- %s (%h)" --invert-grep --grep="^feat" --grep="^fix" >> notes.md || true |
| 138 | + echo "" >> notes.md |
| 139 | + else |
| 140 | + echo "Initial release" >> notes.md |
| 141 | + fi |
| 142 | +
|
| 143 | + echo "" >> notes.md |
| 144 | + echo "### Install" >> notes.md |
| 145 | + echo '```bash' >> notes.md |
| 146 | + echo "npm install -g altimate-code-ai@${CURRENT_TAG#v}" >> notes.md |
| 147 | + echo "# or" >> notes.md |
| 148 | + echo "brew install altimate/tap/altimate-code" >> notes.md |
| 149 | + echo '```' >> notes.md |
| 150 | +
|
| 151 | + echo "" >> notes.md |
| 152 | + echo "**Full Changelog**: https://github.com/${GH_REPO}/compare/${PREV_TAG}...${CURRENT_TAG}" >> notes.md |
| 153 | + env: |
| 154 | + GH_REPO: ${{ env.GH_REPO }} |
| 155 | + CURRENT_TAG: ${{ github.ref_name }} |
| 156 | + |
| 157 | + - name: Download build artifacts |
| 158 | + uses: actions/download-artifact@v4 |
| 159 | + with: |
| 160 | + name: dist |
| 161 | + path: packages/altimate-code/dist/ |
| 162 | + |
| 163 | + - name: Create GitHub Release |
| 164 | + uses: softprops/action-gh-release@v2 |
| 165 | + with: |
| 166 | + body_path: notes.md |
| 167 | + draft: false |
| 168 | + prerelease: ${{ contains(github.ref_name, '-') }} |
| 169 | + files: | |
| 170 | + packages/altimate-code/dist/*.tar.gz |
| 171 | + packages/altimate-code/dist/*.zip |
| 172 | + env: |
| 173 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments