-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(fix): Only publish new version after PR gets merged
- Loading branch information
Mikey Stengel
committed
Oct 8, 2024
1 parent
4de8cb9
commit 49e50dc
Showing
3 changed files
with
41 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
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. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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) | ||
|
This file contains 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