|  | 
|  | 1 | +name: Release | 
|  | 2 | + | 
|  | 3 | +on: | 
|  | 4 | +  push: | 
|  | 5 | +    branches: | 
|  | 6 | +      - main | 
|  | 7 | + | 
|  | 8 | +permissions: | 
|  | 9 | +  contents: write | 
|  | 10 | + | 
|  | 11 | +concurrency: | 
|  | 12 | +  group: release-main | 
|  | 13 | +  cancel-in-progress: true | 
|  | 14 | + | 
|  | 15 | +jobs: | 
|  | 16 | +  read_commit_message: | 
|  | 17 | +    runs-on: ubuntu-latest | 
|  | 18 | +    outputs: | 
|  | 19 | +      skip_release: ${{ steps.compute_msg.outputs.skip_release }} | 
|  | 20 | +    steps: | 
|  | 21 | +      - name: Compute commit flags | 
|  | 22 | +        id: compute_msg | 
|  | 23 | +        shell: bash | 
|  | 24 | +        env: | 
|  | 25 | +          COMMIT_MESSAGE: ${{ github.event.head_commit.message }} | 
|  | 26 | +        run: | | 
|  | 27 | +          set -euo pipefail | 
|  | 28 | +          if printf "%s" "$COMMIT_MESSAGE" | grep -q "chore: release to marketplace and update README.md"; then | 
|  | 29 | +            echo "skip_release=true" >> $GITHUB_OUTPUT | 
|  | 30 | +          else | 
|  | 31 | +            echo "skip_release=false" >> $GITHUB_OUTPUT | 
|  | 32 | +          fi | 
|  | 33 | +  release: | 
|  | 34 | +    needs: read_commit_message | 
|  | 35 | +    if: ${{ needs.read_commit_message.outputs.skip_release != 'true' }} | 
|  | 36 | +    runs-on: ubuntu-latest | 
|  | 37 | +    steps: | 
|  | 38 | +      - name: Checkout | 
|  | 39 | +        uses: actions/checkout@v5 | 
|  | 40 | + | 
|  | 41 | +      - name: Compute next version | 
|  | 42 | +        id: compute | 
|  | 43 | +        shell: bash | 
|  | 44 | +        run: | | 
|  | 45 | +          set -euo pipefail | 
|  | 46 | +          CLI_VERSION=$(grep -E 'npm i -g @posthog/cli@' action.yml | sed -E 's/.*@posthog\/cli@([0-9]+\.[0-9]+\.[0-9]+).*/\1/') | 
|  | 47 | +          README_VERSION_FULL=$(grep -Eo 'uses: .*PostHog/upload-source-maps@v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' -m1 README.md | sed -E 's/.*@v([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\1/' || true) | 
|  | 48 | +          if [ -n "${README_VERSION_FULL:-}" ]; then | 
|  | 49 | +            README_BASE=$(echo "$README_VERSION_FULL" | cut -d. -f1-3) | 
|  | 50 | +            README_BUILD=$(echo "$README_VERSION_FULL" | awk -F. '{print $4}') | 
|  | 51 | +          else | 
|  | 52 | +            README_BASE="" | 
|  | 53 | +            README_BUILD="" | 
|  | 54 | +          fi | 
|  | 55 | +          if [ "$CLI_VERSION" = "$README_BASE" ] && [ -n "${README_BUILD}" ]; then | 
|  | 56 | +            NEW_VERSION="v${CLI_VERSION}.$((README_BUILD + 1))" | 
|  | 57 | +          else | 
|  | 58 | +            NEW_VERSION="v${CLI_VERSION}.0" | 
|  | 59 | +          fi | 
|  | 60 | +          echo "cli_version=$CLI_VERSION" >> $GITHUB_OUTPUT | 
|  | 61 | +          echo "readme_version_full=${README_VERSION_FULL:-}" >> $GITHUB_OUTPUT | 
|  | 62 | +          echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | 
|  | 63 | +
 | 
|  | 64 | +      - name: Update README usage version | 
|  | 65 | +        shell: bash | 
|  | 66 | +        run: | | 
|  | 67 | +          set -euo pipefail | 
|  | 68 | +          NEW_VERSION="${{ steps.compute.outputs.new_version }}" | 
|  | 69 | +          if grep -qE 'PostHog/upload-source-maps@v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' README.md; then | 
|  | 70 | +            sed -Ei "s|PostHog/upload-source-maps@v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|PostHog/upload-source-maps@${NEW_VERSION}|g" README.md | 
|  | 71 | +          else | 
|  | 72 | +            echo "No existing version string found in README.md" >&2 | 
|  | 73 | +          fi | 
|  | 74 | +
 | 
|  | 75 | +      - name: Commit README change | 
|  | 76 | +        id: commit_readme | 
|  | 77 | +        uses: stefanzweifel/git-auto-commit-action@v5 | 
|  | 78 | +        with: | 
|  | 79 | +          commit_message: "chore: release to marketplace and update README.md" | 
|  | 80 | +          branch: main | 
|  | 81 | +          file_pattern: README.md | 
|  | 82 | + | 
|  | 83 | +      - name: Create tag | 
|  | 84 | +        shell: bash | 
|  | 85 | +        run: | | 
|  | 86 | +          set -euo pipefail | 
|  | 87 | +          NEW_VERSION="${{ steps.compute.outputs.new_version }}" | 
|  | 88 | +          COMMIT_SHA="${{ steps.commit_readme.outputs.commit_hash }}" | 
|  | 89 | +          if [ -z "$COMMIT_SHA" ]; then | 
|  | 90 | +            COMMIT_SHA="$(git rev-parse HEAD)" | 
|  | 91 | +          fi | 
|  | 92 | +          git tag "$NEW_VERSION" "$COMMIT_SHA" | 
|  | 93 | +          git push origin "refs/tags/$NEW_VERSION" | 
|  | 94 | +
 | 
|  | 95 | +      - name: Create GitHub Release | 
|  | 96 | +        uses: softprops/action-gh-release@v2 | 
|  | 97 | +        with: | 
|  | 98 | +          tag_name: ${{ steps.compute.outputs.new_version }} | 
|  | 99 | +          make_latest: true | 
|  | 100 | +          generate_release_notes: true | 
0 commit comments