ci: Add a workflow to undo/yank a release, if necessary #10
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: Publish Release | |
| on: | |
| pull_request: | |
| types: | |
| - closed | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| env: | |
| PYTHON_VERSION: "3.11" | |
| UV_VERSION: "0.7.13" | |
| AUTO_VERSION: "11.3.6" | |
| RELEASE_BOT_NAME: "applied-ai-releases[bot]" | |
| RELEASE_BOT_EMAIL: "applied-ai-releases[bot]@users.noreply.github.com" | |
| jobs: | |
| canary-build: | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'auto:release') | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Install Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| with: | |
| version: ${{ env.UV_VERSION }} | |
| enable-cache: true | |
| python-version: ${{ env.PYTHON_VERSION }} # sets UV_PYTHON | |
| cache-dependency-glob: | | |
| pyproject.toml | |
| uv.lock | |
| - name: Install dependencies | |
| run: | | |
| uv sync --frozen | |
| - name: Check that package can be built | |
| run: uv build | |
| release: | |
| needs: canary-build | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'auto:release') | |
| steps: | |
| - name: Generate GitHub App token | |
| id: app_token | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ vars.RELEASE_BOT_APP_ID }} | |
| private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| token: ${{ steps.app_token.outputs.token }} | |
| - name: Download and install auto | |
| run: | | |
| curl -L https://github.com/intuit/auto/releases/download/v${{ env.AUTO_VERSION }}/auto-linux.gz -o auto-linux.gz | |
| gunzip auto-linux.gz | |
| chmod +x auto-linux | |
| sudo mv auto-linux /usr/local/bin/auto | |
| auto --version | |
| - name: Sanity check | |
| env: | |
| GH_TOKEN: ${{ steps.app_token.outputs.token }} | |
| run: | | |
| auto latest --name "${RELEASE_BOT_NAME}" --email "${RELEASE_BOT_EMAIL}" --dry-run -v | |
| - name: Resolve release version | |
| id: latest_release | |
| env: | |
| GH_TOKEN: ${{ steps.app_token.outputs.token }} | |
| run: | | |
| RAW_VERSION="$(auto latest --name "${RELEASE_BOT_NAME}" --email "${RELEASE_BOT_EMAIL}" --dry-run --quiet | tail -n1 | tr -d '\r')" | |
| VERSION="${RAW_VERSION#v}" | |
| if [ -z "$VERSION" ]; then | |
| echo "Could not resolve release version" | |
| exit 1 | |
| fi | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Resolved version: $VERSION" | |
| - name: Apply release version to pyproject.toml | |
| run: | | |
| VERSION="${{ steps.latest_release.outputs.version }}" | |
| sed -i "s/^version = \".*\"$/version = \"${VERSION}\"/" pyproject.toml | |
| grep '^version = ' pyproject.toml | |
| - name: Commit and push pyproject version update | |
| run: | | |
| if git diff --quiet -- pyproject.toml; then | |
| echo "No pyproject version change to commit." | |
| exit 0 | |
| fi | |
| git config user.name "${RELEASE_BOT_NAME}" | |
| git config user.email "${RELEASE_BOT_EMAIL}" | |
| git add pyproject.toml | |
| git commit -m "chore(release): set pyproject version to ${{ steps.latest_release.outputs.version }}" | |
| git push origin HEAD:main | |
| - name: Create Release | |
| env: | |
| GH_TOKEN: ${{ steps.app_token.outputs.token }} | |
| run: | | |
| auto create-labels | |
| auto latest --name "${RELEASE_BOT_NAME}" --email "${RELEASE_BOT_EMAIL}" --no-changelog | |
| build-and-publish: | |
| needs: release | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'auto:release') | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Install Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| with: | |
| version: ${{ env.UV_VERSION }} | |
| enable-cache: true | |
| python-version: ${{ env.PYTHON_VERSION }} # sets UV_PYTHON | |
| cache-dependency-glob: | | |
| pyproject.toml | |
| uv.lock | |
| - name: Install dependencies | |
| run: | | |
| uv sync --frozen | |
| - name: Build package | |
| run: uv build | |
| - name: Publish to PyPI | |
| env: | |
| UV_PUBLISH_TOKEN: ${{ secrets.PYPI }} | |
| run: uv publish |