Skip to content

Commit

Permalink
ci(fix): Only publish new version after PR gets merged
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikey Stengel committed Oct 8, 2024
1 parent 4de8cb9 commit 49e50dc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-beans-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@serlo/editor': patch
---

Internal: Fixed CI workflow to ensure npm publishing and GitHub release creation only occur after pull request merge.
44 changes: 35 additions & 9 deletions .github/workflows/editor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,28 @@ jobs:
echo "already_published=false" >> $GITHUB_OUTPUT
fi
- name: Check for uncommitted changes
- name: Create a new branch for the version bump
if: steps.check_published.outputs.already_published == 'false'
run: |
NEXT_VERSION=$(node -p "require('./packages/editor/package.json').version")
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git checkout -b "release/@serlo/editor-$NEXT_VERSION"
- name: Check if changes occurred after version bump
id: check_changes
run: |
git add .
if git diff --quiet; then
if git diff --exit-code --quiet; then
echo "no_changes=true" >> $GITHUB_OUTPUT
else
echo "no_changes=false" >> $GITHUB_OUTPUT
fi
- name: Create a new branch for the version bump
- name: Commit changes to the new branch
if: steps.check_published.outputs.already_published == 'false' && steps.check_changes.outputs.no_changes == 'false'
run: |
NEXT_VERSION=$(node -p "require('./packages/editor/package.json').version")
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git checkout -b "release/@serlo/editor-$NEXT_VERSION"
git add .
git commit -m "chore(release): bump @serlo/editor to version $NEXT_VERSION"
git push origin "release/@serlo/editor-$NEXT_VERSION"
Expand All @@ -60,20 +65,41 @@ jobs:

- name: Create Pull Request
if: steps.check_published.outputs.already_published == 'false' && steps.check_changes.outputs.no_changes == 'false'
id: create_pr
run: |
NEXT_VERSION=$(node -p "require('./packages/editor/package.json').version")
gh pr create --title "Release: Bump @serlo/editor to version $NEXT_VERSION" --body "Automated PR to bump @serlo/editor to $NEXT_VERSION" --base staging --head "release/@serlo/editor-$NEXT_VERSION"
PR_URL=$(gh pr create --title "Release: Bump @serlo/editor to version $NEXT_VERSION" --body "Automated PR to bump @serlo/editor to $NEXT_VERSION" --base staging --head "release/@serlo/editor-$NEXT_VERSION" --json url -q .url)
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Wait for PR to be merged
if: steps.create_pr.outputs.pr_url
run: |
PR_URL="${{ steps.create_pr.outputs.pr_url }}"
while true; do
PR_STATE=$(gh pr view $PR_URL --json state -q .state)
if [ "$PR_STATE" = "MERGED" ]; then
echo "PR has been merged"
break
elif [ "$PR_STATE" = "CLOSED" ]; then
echo "PR was closed without merging"
exit 1
fi
echo "Waiting for PR to be merged..."
sleep 60
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to npm (after PR merge)
if: steps.check_published.outputs.already_published == 'false'
if: steps.check_published.outputs.already_published == 'false' && steps.create_pr.outputs.pr_url
run: yarn editor:publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create GitHub Release (after PR merge)
if: steps.check_published.outputs.already_published == 'false'
if: steps.check_published.outputs.already_published == 'false' && steps.create_pr.outputs.pr_url
run: |
NEXT_VERSION=$(node -p "require('./packages/editor/package.json').version")
body=$(git log -1 --pretty=format:%B)
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serlo/editor",
"version": "0.15.2",
"version": "0.15.3",
"homepage": "https://de.serlo.org/editor",
"bugs": {
"url": "https://github.com/serlo/frontend/issues"
Expand Down

0 comments on commit 49e50dc

Please sign in to comment.