Merge pull request #1 from chatbotkit/next #1
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: Release | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - VERSION | |
| - .github/workflows/release.yaml | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| if: github.actor != 'github-actions[bot]' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Verify main branch | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if [[ "${GITHUB_REF_NAME}" != "main" ]]; then | |
| echo "Releases can only be published from main" >&2 | |
| exit 1 | |
| fi | |
| - name: Resolve version | |
| id: version | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| raw_version=$(tr -d '[:space:]' < VERSION) | |
| version=${raw_version#v} | |
| if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "VERSION must contain a semantic version like 1.2.3 or v1.2.3" >&2 | |
| exit 1 | |
| fi | |
| semver_tag="v$version" | |
| major_tag="v${version%%.*}" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "semver_tag=$semver_tag" >> "$GITHUB_OUTPUT" | |
| echo "major_tag=$major_tag" >> "$GITHUB_OUTPUT" | |
| - name: Check existing tags | |
| id: tags | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| git fetch --tags --force | |
| semver_tag='${{ steps.version.outputs.semver_tag }}' | |
| current_sha=$(git rev-parse HEAD) | |
| if git rev-parse "$semver_tag" >/dev/null 2>&1; then | |
| existing_sha=$(git rev-list -n 1 "$semver_tag") | |
| if [[ "$existing_sha" == "$current_sha" ]]; then | |
| echo "publish=false" >> "$GITHUB_OUTPUT" | |
| echo "message=Tag $semver_tag already exists on this commit" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| echo "Version tag $semver_tag already exists on a different commit" >&2 | |
| exit 1 | |
| fi | |
| echo "publish=true" >> "$GITHUB_OUTPUT" | |
| echo "message=Publishing $semver_tag from $current_sha" >> "$GITHUB_OUTPUT" | |
| - name: Create release tags | |
| if: steps.tags.outputs.publish == 'true' | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| semver_tag='${{ steps.version.outputs.semver_tag }}' | |
| major_tag='${{ steps.version.outputs.major_tag }}' | |
| git config user.name 'github-actions[bot]' | |
| git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| git tag -a "$semver_tag" -m "Release $semver_tag" | |
| git tag -fa "$major_tag" -m "Release $semver_tag" | |
| git push origin "refs/tags/$semver_tag" | |
| git push origin "refs/tags/$major_tag" --force | |
| - name: Write summary | |
| shell: bash | |
| run: | | |
| { | |
| echo "## Release" | |
| echo | |
| echo "- Version: ${{ steps.version.outputs.semver_tag }}" | |
| echo "- Major tag: ${{ steps.version.outputs.major_tag }}" | |
| echo "- Result: ${{ steps.tags.outputs.message }}" | |
| } >> "$GITHUB_STEP_SUMMARY" |