Skip to content

Commit f8bafed

Browse files
authored
feat: update workflow and cli version (#8)
* update workflow and cli version * update readme
1 parent bc6440d commit f8bafed

File tree

4 files changed

+29
-61
lines changed

4 files changed

+29
-61
lines changed

.github/workflows/release.yml

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,90 +10,49 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13-
read_commit_message:
14-
runs-on: ubuntu-latest
15-
outputs:
16-
skip_release: ${{ steps.compute_msg.outputs.skip_release }}
17-
steps:
18-
- name: Compute commit flags
19-
id: compute_msg
20-
shell: bash
21-
env:
22-
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
23-
run: |
24-
set -euo pipefail
25-
if printf "%s" "$COMMIT_MESSAGE" | grep -q "chore: release to marketplace and update README.md"; then
26-
echo "skip_release=true" >> $GITHUB_OUTPUT
27-
else
28-
echo "skip_release=false" >> $GITHUB_OUTPUT
29-
fi
3013
release:
31-
needs: read_commit_message
32-
if: ${{ needs.read_commit_message.outputs.skip_release != 'true' }}
3314
runs-on: ubuntu-latest
3415
permissions:
3516
contents: write
3617
steps:
3718
- name: Checkout
3819
uses: actions/checkout@v5
20+
with:
21+
fetch-depth: 0
3922

40-
- name: Compute next version
41-
id: compute
23+
- name: Read version from file
24+
id: version
4225
shell: bash
4326
run: |
4427
set -euo pipefail
45-
CLI_VERSION=$(grep -E 'npm i -g @posthog/cli@' action.yml | sed -E 's/.*@posthog\/cli@([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
46-
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)
47-
if [ -n "${README_VERSION_FULL:-}" ]; then
48-
README_BASE=$(echo "$README_VERSION_FULL" | cut -d. -f1-3)
49-
README_BUILD=$(echo "$README_VERSION_FULL" | awk -F. '{print $4}')
50-
else
51-
README_BASE=""
52-
README_BUILD=""
53-
fi
54-
if [ "$CLI_VERSION" = "$README_BASE" ] && [ -n "${README_BUILD}" ]; then
55-
NEW_VERSION="v${CLI_VERSION}.$((README_BUILD + 1))"
56-
else
57-
NEW_VERSION="v${CLI_VERSION}.0"
58-
fi
59-
echo "cli_version=$CLI_VERSION" >> $GITHUB_OUTPUT
60-
echo "readme_version_full=${README_VERSION_FULL:-}" >> $GITHUB_OUTPUT
61-
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
28+
VERSION=$(cat VERSION | tr -d '[:space:]')
29+
echo "version=v${VERSION}" >> $GITHUB_OUTPUT
6230
63-
- name: Update README usage version
31+
- name: Check if tag exists
32+
id: check_tag
6433
shell: bash
6534
run: |
6635
set -euo pipefail
67-
NEW_VERSION="${{ steps.compute.outputs.new_version }}"
68-
if grep -qE 'PostHog/upload-source-maps@v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' README.md; then
69-
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
36+
VERSION="${{ steps.version.outputs.version }}"
37+
if git rev-parse "$VERSION" >/dev/null 2>&1; then
38+
echo "exists=true" >> $GITHUB_OUTPUT
7039
else
71-
echo "No existing version string found in README.md" >&2
40+
echo "exists=false" >> $GITHUB_OUTPUT
7241
fi
7342
74-
- name: Commit README change
75-
id: commit_readme
76-
uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3 # v7.0.0
77-
with:
78-
commit_message: "chore: release to marketplace and update README.md"
79-
branch: main
80-
file_pattern: README.md
81-
8243
- name: Create tag
44+
if: steps.check_tag.outputs.exists == 'false'
8345
shell: bash
8446
run: |
8547
set -euo pipefail
86-
NEW_VERSION="${{ steps.compute.outputs.new_version }}"
87-
COMMIT_SHA="${{ steps.commit_readme.outputs.commit_hash }}"
88-
if [ -z "$COMMIT_SHA" ]; then
89-
COMMIT_SHA="$(git rev-parse HEAD)"
90-
fi
91-
git tag "$NEW_VERSION" "$COMMIT_SHA"
92-
git push origin "refs/tags/$NEW_VERSION"
48+
VERSION="${{ steps.version.outputs.version }}"
49+
git tag "$VERSION"
50+
git push origin "refs/tags/$VERSION"
9351
9452
- name: Create GitHub Release
53+
if: steps.check_tag.outputs.exists == 'false'
9554
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
9655
with:
97-
tag_name: ${{ steps.compute.outputs.new_version }}
56+
tag_name: ${{ steps.version.outputs.version }}
9857
make_latest: true
9958
generate_release_notes: true

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ See the PostHog documentation for end-to-end guidance: [Upload source maps](http
2323
| `skip-ssl-verification` | No | Whether to skip SSL verification when uploading chunks - only use when using self-signed certificates for self-deployed instances (default: `false`) |
2424
| `batch-size` | No | The maximum number of chunks to upload in a single batch (default: 50) |
2525
| `ignore` | No | One or more directory glob patterns to ignore (comma-separated, e.g., `node_modules,*.test.js`) |
26+
| `cli-version` | No | PostHog CLI version to use (e.g., `0.5.7`). If not provided, the latest version is used |
2627

2728
## Example usage
2829

@@ -48,7 +49,7 @@ jobs:
4849

4950
# Inject and upload source maps using this action
5051
- name: Inject & upload source maps to PostHog
51-
uses: PostHog/upload-source-maps@v0.5.7.0
52+
uses: PostHog/upload-source-maps@v1
5253
with:
5354
directory: dist
5455
env-id: ${{ secrets.POSTHOG_ENV_ID }}
@@ -74,4 +75,7 @@ jobs:
7475

7576
# Ignore specific patterns
7677
# ignore: node_modules,*.test.js,coverage
78+
79+
# Pin to a specific CLI version
80+
# cli-version: 0.5.7
7781
```

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ inputs:
4141
ignore:
4242
description: "One or more directory glob patterns to ignore (comma-separated)"
4343
required: false
44+
cli-version:
45+
description: "PostHog CLI version to use (e.g., '0.5.7'). If not provided, the latest version is used"
46+
required: false
47+
default: "latest"
4448

4549
runs:
4650
using: "composite"
4751
steps:
4852
- name: Install posthog CLI
4953
shell: bash
50-
run: npm i -g @posthog/cli@0.5.7
54+
run: npm i -g @posthog/cli@${{ inputs.cli-version }}
5155

5256
- name: Upload sourcemaps
5357
shell: bash

0 commit comments

Comments
 (0)