-
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(editor): Write custom github action for generating changelog from …
…PR names and throw out the changeset package
- Loading branch information
Mikey Stengel
committed
Oct 9, 2024
1 parent
46fb167
commit bc1fd0f
Showing
53 changed files
with
112 additions
and
577 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,84 @@ | ||
name: Generate Editor Changelog | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' # Runs on all branches | ||
|
||
jobs: | ||
generate-changelog: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Get current version of editor package | ||
id: get_local_version | ||
run: echo "CURRENT_VERSION=$(node -p \"require('./packages/editor/package.json').version\")" >> $GITHUB_ENV | ||
|
||
- name: Get latest published version from npm | ||
id: get_npm_version | ||
run: | | ||
NPM_VERSION=$(npm view @serlo/editor version) | ||
echo "NPM_VERSION=$NPM_VERSION" >> $GITHUB_ENV | ||
- name: Check if version has changed | ||
id: check_version | ||
run: | | ||
if [ "$CURRENT_VERSION" != "$NPM_VERSION" ]; then | ||
echo "version_changed=true" >> $GITHUB_ENV | ||
else | ||
echo "version_changed=false" >> $GITHUB_ENV | ||
- name: Stop if version has not changed | ||
if: env.version_changed == 'false' | ||
run: exit 0 | ||
|
||
- name: Get last tag for editor package | ||
id: get_last_tag | ||
run: | | ||
git fetch --all --tags | ||
LAST_TAG=$(git describe --tags --match "v*" --abbrev=0 -- packages/editor) | ||
echo "LAST_TAG=$LAST_TAG" >> $GITHUB_ENV | ||
- name: Get merged PRs affecting editor package | ||
id: get_prs | ||
run: | | ||
PRS=$(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls?state=closed&per_page=100" | jq -r '.[] | select(.merged_at != null and .merged_at > $GITHUB_ENV.LAST_TAG and .head.repo.full_name == "${{ github.repository }}") | .number') | ||
echo "PR_NUMBERS=$PRS" >> $GITHUB_ENV | ||
- name: Get PR titles that touched editor folder | ||
id: get_pr_titles | ||
run: | | ||
for pr in $PRS; do | ||
FILES=$(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/$pr/files" | jq -r '.[].filename') | ||
if echo "$FILES" | grep -q "^packages/editor/"; then | ||
PR_TITLE=$(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/$pr" | jq -r '.title') | ||
echo "$PR_TITLE" >> pr_titles.txt | ||
fi | ||
done | ||
shell: bash | ||
|
||
- name: Generate Changelog | ||
run: | | ||
echo "## Changelog for version $CURRENT_VERSION" > packages/editor/CHANGELOG.md | ||
if [ -f pr_titles.txt ]; then | ||
while IFS= read -r title; do | ||
echo "- $title" >> packages/editor/CHANGELOG.md | ||
done < pr_titles.txt | ||
fi | ||
- name: Commit and Push Changelog | ||
run: | | ||
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "GitHub Action Bot" | ||
git add packages/editor/CHANGELOG.md | ||
git commit -m "chore: update changelog for version $CURRENT_VERSION" | ||
git push origin ${{ github.ref_name }} |
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 |
---|---|---|
|
@@ -11,98 +11,46 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: https://registry.npmjs.org | ||
|
||
- run: yarn | ||
|
||
- name: Build editor package | ||
run: yarn editor:build | ||
|
||
- name: Apply Changesets and Version Bump | ||
run: yarn changeset version | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Check if the next version is already published | ||
- name: Check if current version is already published | ||
id: check_published | ||
run: | | ||
NEXT_VERSION=$(node -p "require('./packages/editor/package.json').version") | ||
if npm view @serlo/editor@$NEXT_VERSION > /dev/null 2>&1; then | ||
CURRENT_VERSION=$(node -p "require('./packages/editor/package.json').version") | ||
if npm view @serlo/editor@$CURRENT_VERSION > /dev/null 2>&1; then | ||
echo "already_published=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "already_published=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Create a new branch for the version bump | ||
- name: Publish to npm | ||
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 --exit-code --quiet; then | ||
echo "no_changes=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "no_changes=false" >> $GITHUB_OUTPUT | ||
fi | ||
- 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 add . | ||
git commit -m "chore(release): bump @serlo/editor to version $NEXT_VERSION" | ||
git push origin "release/@serlo/editor-$NEXT_VERSION" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- 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") | ||
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' && 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' && steps.create_pr.outputs.pr_url | ||
- name: Create and push Git tag | ||
if: steps.check_published.outputs.already_published == 'false' | ||
run: | | ||
NEXT_VERSION=$(node -p "require('./packages/editor/package.json').version") | ||
body=$(git log -1 --pretty=format:%B) | ||
gh release create "v$NEXT_VERSION" --notes "$body" | ||
VERSION=$(node -p "require('./packages/editor/package.json').version") | ||
git tag v$VERSION | ||
git push origin v$VERSION | ||
- name: Create GitHub Release | ||
if: steps.check_published.outputs.already_published == 'false' | ||
uses: actions/create-release@v1 | ||
with: | ||
tag_name: v${{ steps.check_published.outputs.CURRENT_VERSION }} | ||
release_name: v${{ steps.check_published.outputs.CURRENT_VERSION }} | ||
draft: false | ||
prerelease: false | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Binary file not shown.
Binary file removed
BIN
-39.3 KB
.yarn/cache/@changesets-apply-release-plan-npm-7.0.5-6b00e73620-f6a1b90d89.zip
Binary file not shown.
Binary file removed
BIN
-42.3 KB
.yarn/cache/@changesets-assemble-release-plan-npm-6.0.4-999d754646-948066a8ca.zip
Binary file not shown.
Binary file removed
BIN
-7.48 KB
.yarn/cache/@changesets-changelog-git-npm-0.2.0-9b2795d69d-132660f7fd.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-13.1 KB
.yarn/cache/@changesets-get-dependents-graph-npm-2.1.2-f4de93cc8e-38446343e4.zip
Binary file not shown.
Binary file removed
BIN
-11.1 KB
.yarn/cache/@changesets-get-release-plan-npm-4.0.4-9e9e65d37b-7217347f5b.zip
Binary file not shown.
Binary file removed
BIN
-7.46 KB
.yarn/cache/@changesets-get-version-range-type-npm-0.4.0-49cc1009b2-2e8c511e65.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-5.45 KB
.yarn/cache/@changesets-should-skip-package-npm-0.1.1-3ecc38a85f-d187ef2249.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-11.1 KB
.yarn/cache/@manypkg-get-packages-npm-1.1.3-55c0cc9daa-f5a756e5a6.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-2.51 KB
.yarn/cache/better-path-resolve-npm-1.0.0-ea479f476b-5392dbe04e.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-17.5 KB
.yarn/cache/package-manager-detector-npm-0.2.1-1203c5038d-79000d6bad.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Oops, something went wrong.