Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(editor): Write custom github action for generating changelog from PR names and throw out the changeset package #4171

Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bc1fd0f
ci(editor): Write custom github action for generating changelog from …
Oct 9, 2024
a6057ce
ci(fix): Throw out unused branch and fix syntax
Oct 9, 2024
f1eea16
fix(ci): Close if else conditional
Oct 9, 2024
b0e6eeb
fix(ci): More improvements and check for changed files since the last…
Oct 9, 2024
7c7c516
fix(ci): No editor changes instead of editor changes
Oct 9, 2024
23fa59b
refactor(ci): Last 10 PRs if no previous tag was found
Oct 9, 2024
05f0311
chore(editor): Bump version to see if changelogs get generated
Oct 9, 2024
c0a39ea
refactor(ci): Generate changelog only when it does not exist
Oct 9, 2024
425b92d
fix(ci): If no tag has been pushed yet, it should assume there are ch…
Oct 9, 2024
47f82d7
fix(ci): Handle list of PR numbers properly
Oct 9, 2024
be12aa1
chore: update changelog for version 0.15.4
github-actions[bot] Oct 9, 2024
b0a54ae
fix(ci): Move from temporary file (empty changelog) to a variable to …
Oct 9, 2024
85c3285
chore: update changelog for version 0.15.4
github-actions[bot] Oct 9, 2024
0f4ad98
fix(ci): Only write changelog if we have PR titles
Oct 9, 2024
8487747
chore: update changelog for version 0.15.4
github-actions[bot] Oct 9, 2024
e6cbae5
fix(ci): Try another approach to PR titles
Oct 9, 2024
21e2250
Merge remote-tracking branch 'origin/chore/delete-change-sets-and-wri…
Oct 9, 2024
ec00646
ci(editor): Delete changelog
Oct 9, 2024
b995226
debug(ci): Check why PR titles are still empty
Oct 9, 2024
8e9fccd
debug(ci): More logs
Oct 9, 2024
cb0e432
chore: update changelog for version 0.15.4
github-actions[bot] Oct 9, 2024
c967d99
Merge branch 'staging' into chore/delete-change-sets-and-write-custom…
Oct 10, 2024
f67a4b5
ci(editor): Extract the changelog and use more up-to-date github action
Oct 10, 2024
d3be2df
fix(ci): Add newline, make prettier happy
Oct 10, 2024
d9274a1
refactor(editor): Implement feedback of Hugo and make Github action m…
CodingDive Oct 10, 2024
59238d5
Merge branch 'staging' into chore/delete-change-sets-and-write-custom…
CodingDive Oct 10, 2024
7c53936
ci(editor): Run prettier on changelog file instead of ignoring it
Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .changeset/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions .changeset/config.json

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/gentle-cherries-flow.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/hip-moose-relate.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/yellow-beans-kiss.md

This file was deleted.

168 changes: 168 additions & 0 deletions .github/workflows/editor-changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Generate Editor Changelog
hugotiburtino marked this conversation as resolved.
Show resolved Hide resolved

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: |
CURRENT_VERSION=$(node -p "require('./packages/editor/package.json').version")
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV

- name: Check if changelog for this version already exists
id: check_existing_changelog
run: |
if [ -f packages/editor/CHANGELOG.md ] && grep -q "## Changelog for version $CURRENT_VERSION" packages/editor/CHANGELOG.md; then
echo "changelog_exists=true" >> $GITHUB_ENV
else
echo "changelog_exists=false" >> $GITHUB_ENV
fi

- name: Get latest published version from npm
if: env.changelog_exists == 'false'
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
if: env.changelog_exists == 'false'
id: check_version
run: |
if [ "$CURRENT_VERSION" != "$NPM_VERSION" ]; then
echo "version_changed=true" >> $GITHUB_ENV
else
echo "version_changed=false" >> $GITHUB_ENV
fi

- name: Stop if version has not changed
if: env.version_changed == 'false'
run: exit 0

- name: Get last tag for editor package (if available)
if: env.version_changed == 'true'
id: get_last_tag
run: |
git fetch --all --tags
LAST_TAG=$(git describe --tags --match "v*-editor" --abbrev=0 2>/dev/null || echo "none")
if [ "$LAST_TAG" == "none" ]; then
echo "No previous tag found, this is the first release"
echo "LAST_TAG=" >> $GITHUB_ENV
else
echo "LAST_TAG=$LAST_TAG" >> $GITHUB_ENV
fi

- name: Check if there are changes in packages/editor since last tag
if: env.version_changed == 'true'
id: check_editor_changes
run: |
if [ -z "$LAST_TAG" ]; then
# No previous tag, assume all changes in editor are new
echo "no_editor_changes=false" >> $GITHUB_ENV
else
# Compare changes since the last tag
CHANGED_FILES=$(git diff --name-only $LAST_TAG HEAD -- packages/editor)
if [ -z "$CHANGED_FILES" ]; then
echo "no_editor_changes=true" >> $GITHUB_ENV
else
echo "no_editor_changes=false" >> $GITHUB_ENV
fi
fi

- name: Stop if no changes in packages/editor
if: env.no_editor_changes == 'true'
run: exit 0

- name: Get merged PRs affecting editor package (last 10 if no tag)
if: env.version_changed == 'true' && env.no_editor_changes == 'false'
id: get_prs
run: |
if [ -z "$LAST_TAG" ]; then
# No tag, get last 10 PRs
PRS=$(curl -s "https://api.github.com/repos/serlo/frontend/pulls?state=closed&per_page=10" | jq -r '.[] | .number' | tr '\n' ' ')
else
# Fetch PRs since last tag
PRS=$(curl -s "https://api.github.com/repos/serlo/frontend/pulls?state=closed&per_page=100" | jq -r '.[] | select(.merged_at != null and .merged_at > $GITHUB_ENV.LAST_TAG and .head.repo.full_name == "serlo/frontend") | .number' | tr '\n' ' ')
fi
echo "PR_NUMBERS=$PRS" >> $GITHUB_ENV

- name: Get PR titles that touched editor folder
if: env.version_changed == 'true' && env.no_editor_changes == 'false'
id: get_pr_titles
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_TITLES=""
IFS=' ' read -r -a PR_ARRAY <<< "$PR_NUMBERS"
echo "Processing ${#PR_ARRAY[@]} PRs"
for pr in "${PR_ARRAY[@]}"; do
echo "Checking PR #$pr"
PR_DATA=$(curl -s -H "Authorization: token $GH_TOKEN" "https://api.github.com/repos/${{ github.repository }}/pulls/$pr")
if [ $? -ne 0 ]; then
echo "Error fetching PR data for #$pr"
continue
fi

MERGED=$(echo "$PR_DATA" | jq -r '.merged')
if [ "$MERGED" != "true" ]; then
echo "PR #$pr was not merged, skipping"
continue
fi

FILES=$(curl -s -H "Authorization: token $GH_TOKEN" "https://api.github.com/repos/${{ github.repository }}/pulls/$pr/files")
if [ $? -ne 0 ]; then
echo "Error fetching files for PR #$pr"
continue
fi

if echo "$FILES" | jq -r '.[].filename' | grep -q "^packages/editor/"; then
PR_TITLE=$(echo "$PR_DATA" | jq -r '.title')
echo "PR #$pr touches editor package. Title: $PR_TITLE"
PR_TITLES="${PR_TITLES}- ${PR_TITLE}\n"
else
echo "PR #$pr does not touch editor package"
fi
done
echo "Final PR_TITLES: $PR_TITLES"
if [ -n "$PR_TITLES" ]; then
# Escape special characters and set PR_TITLES as an environment variable
escaped_titles=$(printf '%s\n' "$PR_TITLES" | sed -e 's/"/\\"/g' -e 's/!/\\!/g')
echo "PR_TITLES<<EOF" >> $GITHUB_ENV
echo "$escaped_titles" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
else
echo "PR_TITLES=No relevant PRs found" >> $GITHUB_ENV
fi
shell: bash

- name: Generate Changelog
if: env.version_changed == 'true' && env.no_editor_changes == 'false' && env.PR_TITLES != 'No relevant PRs found'
run: |
echo "## Changelog for version $CURRENT_VERSION" > packages/editor/CHANGELOG.md
echo "" >> packages/editor/CHANGELOG.md # Adds a newline after the heading
echo -e "$PR_TITLES" >> packages/editor/CHANGELOG.md

- name: Commit and Push Changelog
if: env.version_changed == 'true' && env.no_editor_changes == 'false' && env.PR_TITLES != 'No relevant PRs found'
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 }}
105 changes: 33 additions & 72 deletions .github/workflows/editor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,66 @@ on:
push:
branches:
- staging
- editor-package-vite

jobs:
build-and-publish:
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: Get current version from package.json
id: get_version
run: echo "CURRENT_VERSION=$(node -p "require('./packages/editor/package.json').version")" >> $GITHUB_ENV

- 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
CodingDive marked this conversation as resolved.
Show resolved Hide resolved
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"
run: yarn editor:publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create Pull Request
if: steps.check_published.outputs.already_published == 'false' && steps.check_changes.outputs.no_changes == 'false'
id: create_pr
- 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")
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 }}
VERSION=$(node -p "require('./packages/editor/package.json').version")
git tag v$VERSION
git push origin v$VERSION

- name: Wait for PR to be merged
if: steps.create_pr.outputs.pr_url
- name: Extract changelog for current version
id: extract_changelog
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 }}
CURRENT_VERSION=$(node -p "require('./packages/editor/package.json').version")
CodingDive marked this conversation as resolved.
Show resolved Hide resolved
CHANGELOG=$(awk "/## Changelog for version $CURRENT_VERSION/,/^##/" packages/editor/CHANGELOG.md | sed '$d')
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
echo "$CHANGELOG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

- name: Create GitHub Release (after PR merge)
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)
gh release create "v$NEXT_VERSION" --notes "$body"
- name: Create GitHub Release
if: steps.check_published.outputs.already_published == 'false'
uses: elgohr/Github-Release-Action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: v${{ steps.get_version.outputs.CURRENT_VERSION }}
title: 'Serlo Editor - v${{ steps.get_version.outputs.CURRENT_VERSION }}'
body: |
## Serlo Editor Release Notes
${{ env.RELEASE_NOTES }}
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 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 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 .yarn/cache/mri-npm-1.2.0-8ecee0357d-83f515abbc.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/pify-npm-4.0.1-062756097b-9c4e34278c.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.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"test": "yarn workspace @serlo/frontend test"
},
"devDependencies": {
"@changesets/cli": "^2.27.9",
"@serlo/eslint-config": "workspace:*",
"@serlo/typescript-config": "workspace:*",
"cross-env": "^7.0.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# this also checks .gitignore

dist
dist
CHANGELOG.md
CodingDive marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Changelog for version 0.15.4

- ci(fix): Only publish new version after PR gets merged
- Ci/GitHub action creates pr with changeset
- refactor: move experiments to editor
- fix(plugin-rows): hydration error in anchor link copy tool
- fix(exercise): update titles
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.3",
"version": "0.15.4",
"homepage": "https://de.serlo.org/editor",
"bugs": {
"url": "https://github.com/serlo/frontend/issues"
Expand Down
Loading