Skip to content

Commit bfe2e16

Browse files
authored
Sign commits during release process (#108)
* Sign commits during release process * Fix semgrep findings
1 parent 9af83a0 commit bfe2e16

2 files changed

Lines changed: 25 additions & 41 deletions

File tree

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/checkout@v2
2020

2121
- name: Set up PHP ${{ matrix.php-version }}
22-
uses: shivammathur/setup-php@v2
22+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2.37.0
2323
with:
2424
php-version: ${{ matrix.php-version }}
2525
extensions: xdebug
@@ -45,7 +45,7 @@ jobs:
4545
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
4646
php phpcs.phar --version
4747
48-
- uses: tinovyatkin/action-php-codesniffer@v1
48+
- uses: tinovyatkin/action-php-codesniffer@0043b33b3629611c37e8bc7ee8a4e061dc9a7ea2 # v1
4949
with:
5050
files: "**.php" # you may customize glob as needed
5151
phpcs_path: php phpcs.phar

.github/workflows/release.yml

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@ jobs:
9797
fetch-depth: 0
9898
token: ${{ steps.releaser.outputs.token }}
9999

100-
- name: Configure Git
101-
run: |
102-
git config user.name "github-actions[bot]"
103-
git config user.email "github-actions[bot]@users.noreply.github.com"
104-
105100
- name: Bump version
106101
id: bump-version
107102
run: |
@@ -125,53 +120,42 @@ jobs:
125120
echo "current_version=$current_version" >> $GITHUB_OUTPUT
126121
echo "new_version=$new_version" >> $GITHUB_OUTPUT
127122
123+
if ! git diff --quiet lib/PostHog.php composer.json; then
124+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
125+
else
126+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
127+
fi
128+
128129
- name: Update CHANGELOG.md
130+
env:
131+
CURRENT_VERSION: ${{ steps.bump-version.outputs.current_version }}
132+
NEW_VERSION: ${{ steps.bump-version.outputs.new_version }}
129133
run: |
130-
current_version="${{ steps.bump-version.outputs.current_version }}"
131-
new_version="${{ steps.bump-version.outputs.new_version }}"
132134
release_date=$(date +%Y-%m-%d)
133-
echo -e "## $new_version - $release_date\n\n* [Full Changelog](https://github.com/PostHog/posthog-php/compare/${current_version}...${new_version})\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
135+
echo -e "## $NEW_VERSION - $release_date\n\n* [Full Changelog](https://github.com/PostHog/posthog-php/compare/${CURRENT_VERSION}...${NEW_VERSION})\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
134136
135137
- name: Commit version bump
136-
id: commit-version-bump
137-
run: |
138-
git add lib/PostHog.php composer.json CHANGELOG.md
139-
if git diff --staged --quiet; then
140-
echo "No changes to commit"
141-
echo "committed=false" >> "$GITHUB_OUTPUT"
142-
else
143-
git commit -m "chore: bump version to ${{ steps.bump-version.outputs.new_version }} [version bump]"
144-
git push origin master
145-
echo "committed=true" >> "$GITHUB_OUTPUT"
146-
fi
138+
if: steps.bump-version.outputs.has_changes == 'true'
139+
uses: planetscale/ghcommit-action@25309d8005ac7c3bcd61d3fe19b69e0fe47dbdde # v0.2.20
140+
with:
141+
commit_message: "chore: bump version to ${{ steps.bump-version.outputs.new_version }} [version bump]"
142+
repo: ${{ github.repository }}
143+
branch: master
144+
file_pattern: "lib/PostHog.php composer.json CHANGELOG.md"
147145
env:
148146
GITHUB_TOKEN: ${{ steps.releaser.outputs.token }}
149147

150-
- name: Create and push tag
151-
if: steps.commit-version-bump.outputs.committed == 'true'
152-
run: |
153-
git tag -a "${{ steps.bump-version.outputs.new_version }}" -m "${{ steps.bump-version.outputs.new_version }}"
154-
git push origin "${{ steps.bump-version.outputs.new_version }}"
155-
156148
- name: Create GitHub release
157-
if: steps.commit-version-bump.outputs.committed == 'true'
149+
if: steps.bump-version.outputs.has_changes == 'true'
158150
env:
159151
GH_TOKEN: ${{ steps.releaser.outputs.token }}
152+
NEW_VERSION: ${{ steps.bump-version.outputs.new_version }}
160153
run: |
161-
# Extract the latest changelog entry
162154
LAST_CHANGELOG_ENTRY=$(awk -v defText="see CHANGELOG.md" '/^## /{if (flag) exit; flag=1} flag && /^##$/{exit} flag; END{if (!flag) print defText}' CHANGELOG.md)
163-
gh api \
164-
--method POST \
165-
-H "Accept: application/vnd.github+json" \
166-
-H "X-GitHub-Api-Version: 2022-11-28" \
167-
/repos/PostHog/posthog-php/releases \
168-
-f tag_name="${{ steps.bump-version.outputs.new_version }}" \
169-
-f target_commitish='master' \
170-
-f name="${{ steps.bump-version.outputs.new_version }}" \
171-
-f body="$LAST_CHANGELOG_ENTRY" \
172-
-F draft=false \
173-
-F prerelease=false \
174-
-F generate_release_notes=false
155+
gh release create "$NEW_VERSION" \
156+
--target master \
157+
--title "$NEW_VERSION" \
158+
--notes "$LAST_CHANGELOG_ENTRY"
175159
176160
# Notify in case of a failure
177161
- name: Send failure event to PostHog

0 commit comments

Comments
 (0)