|
| 1 | +name: Release / mem0-aio |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request_target: |
| 6 | + types: [closed] |
| 7 | + |
| 8 | +jobs: |
| 9 | + prepare-release: |
| 10 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + - name: Install git-cliff |
| 21 | + env: |
| 22 | + GIT_CLIFF_VERSION: 2.12.0 |
| 23 | + run: | |
| 24 | + archive="git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-gnu.tar.gz" |
| 25 | + curl -fsSL -o "/tmp/${archive}" "https://github.com/orhun/git-cliff/releases/download/v${GIT_CLIFF_VERSION}/${archive}" |
| 26 | + tar -xzf "/tmp/${archive}" -C /tmp |
| 27 | + install "/tmp/git-cliff-${GIT_CLIFF_VERSION}/git-cliff" /usr/local/bin/git-cliff |
| 28 | + - name: Compute release version |
| 29 | + id: version |
| 30 | + run: echo "release_version=$(python3 scripts/release.py next-version)" >> "${GITHUB_OUTPUT}" |
| 31 | + - name: Generate changelog |
| 32 | + env: |
| 33 | + GITHUB_REPO: ${{ github.repository }} |
| 34 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + RELEASE_VERSION: ${{ steps.version.outputs.release_version }} |
| 36 | + run: git-cliff --config cliff.toml --tag "${RELEASE_VERSION}" --output CHANGELOG.md |
| 37 | + - name: Create release PR |
| 38 | + uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0 |
| 39 | + with: |
| 40 | + commit-message: "chore(release): ${{ steps.version.outputs.release_version }}" |
| 41 | + title: "chore(release): ${{ steps.version.outputs.release_version }}" |
| 42 | + body: | |
| 43 | + This PR prepares `${{ steps.version.outputs.release_version }}`. |
| 44 | + branch: "release/${{ steps.version.outputs.release_version }}" |
| 45 | + delete-branch: true |
| 46 | + |
| 47 | + publish-release-on-merge: |
| 48 | + if: "${{ github.event_name == 'pull_request_target' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && startsWith(github.event.pull_request.title, 'chore(release): ') }}" |
| 49 | + runs-on: ubuntu-latest |
| 50 | + permissions: |
| 51 | + contents: write |
| 52 | + steps: |
| 53 | + - name: Checkout merge commit |
| 54 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 55 | + with: |
| 56 | + ref: ${{ github.event.pull_request.merge_commit_sha }} |
| 57 | + fetch-depth: 0 |
| 58 | + - name: Determine release version |
| 59 | + id: version |
| 60 | + env: |
| 61 | + PR_TITLE: ${{ github.event.pull_request.title }} |
| 62 | + run: | |
| 63 | + release_version="${PR_TITLE#chore(release): }" |
| 64 | + echo "release_version=${release_version}" >> "${GITHUB_OUTPUT}" |
| 65 | + test "$(python3 scripts/release.py latest-changelog-version)" = "${release_version}" |
| 66 | + - name: Extract release notes |
| 67 | + id: notes |
| 68 | + env: |
| 69 | + RELEASE_VERSION: ${{ steps.version.outputs.release_version }} |
| 70 | + run: | |
| 71 | + { |
| 72 | + echo "release_notes<<EOF" |
| 73 | + python3 scripts/release.py extract-release-notes "${RELEASE_VERSION}" |
| 74 | + echo "EOF" |
| 75 | + } >> "${GITHUB_OUTPUT}" |
| 76 | + - name: Create Git tag if missing |
| 77 | + env: |
| 78 | + RELEASE_VERSION: ${{ steps.version.outputs.release_version }} |
| 79 | + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} |
| 80 | + run: | |
| 81 | + if git rev-parse "${RELEASE_VERSION}" >/dev/null 2>&1; then exit 0; fi |
| 82 | + git config user.name "github-actions[bot]" |
| 83 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 84 | + git tag "${RELEASE_VERSION}" "${MERGE_SHA}" |
| 85 | + git push origin "${RELEASE_VERSION}" |
| 86 | + - name: Publish GitHub release |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + RELEASE_VERSION: ${{ steps.version.outputs.release_version }} |
| 90 | + RELEASE_NOTES: ${{ steps.notes.outputs.release_notes }} |
| 91 | + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} |
| 92 | + run: | |
| 93 | + if gh release view "${RELEASE_VERSION}" >/dev/null 2>&1; then exit 0; fi |
| 94 | + notes_file="$(mktemp)" |
| 95 | + printf '%s\n' "${RELEASE_NOTES}" > "${notes_file}" |
| 96 | + gh release create "${RELEASE_VERSION}" --title "${RELEASE_VERSION}" --notes-file "${notes_file}" --target "${MERGE_SHA}" |
0 commit comments