Merge pull request #4379 from serlo/math-renderer-sanitize-html #931
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
name: editor | |
on: | |
push: | |
branches: | |
- staging | |
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: Get current version from package.json | |
id: get_version | |
run: | | |
VERSION=$(node -p "require('./packages/editor/package.json').version") | |
echo "CURRENT_VERSION=$VERSION" >> $GITHUB_ENV | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Check if current version is already published | |
id: check_published | |
run: | | |
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: Publish to npm | |
if: steps.check_published.outputs.already_published == 'false' | |
run: yarn editor:publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Create and push Git tag | |
if: steps.check_published.outputs.already_published == 'false' | |
run: | | |
TAG_NAME="v${CURRENT_VERSION}-editor" | |
git tag "$TAG_NAME" | |
git push origin "$TAG_NAME" | |
- name: Extract changelog for current version | |
id: extract_changelog | |
run: | | |
echo "Extracting changelog for version $CURRENT_VERSION" | |
CHANGELOG=$(awk -v ver="$CURRENT_VERSION" ' | |
$0 == "## Changelog for version " ver { | |
flag=1; | |
next | |
} | |
$0 ~ /^## / { | |
if(flag) exit | |
} | |
flag { print } | |
' packages/editor/CHANGELOG.md) | |
echo "CHANGELOG<<EOF" >> $GITHUB_ENV | |
echo "$CHANGELOG" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
# Debug output since sometimes the body does not get published | |
echo "Extracted changelog:" | |
echo "$CHANGELOG" | |
- name: Create GitHub Release | |
if: steps.check_published.outputs.already_published == 'false' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
RELEASE_VERSION: ${{ steps.get_version.outputs.version }} | |
run: | | |
TAG_NAME="v${RELEASE_VERSION}-editor" | |
# Debugging again | |
echo "Release body:" | |
echo "$CHANGELOG" | |
curl -X POST \ | |
-H "Authorization: token $GH_TOKEN" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/releases \ | |
-d @- << EOF | |
{ | |
"tag_name": "${TAG_NAME}", | |
"name": "Serlo Editor - v${RELEASE_VERSION}", | |
"body": $(echo "$CHANGELOG" | jq -Rs .) | |
} | |
EOF |