Co-Authored-By: elad_pt <124190990+elad-pticha@users.noreply.github.com>
This commit is contained in:
Timothy J. Baek 2024-08-19 14:01:21 +02:00
parent 13b0e7d64a
commit b4de0a52f8

View File

@ -10,61 +10,63 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Check for changes in package.json - name: Check for changes in package.json
run: | run: |
git diff --cached --diff-filter=d package.json || { git diff --cached --diff-filter=d package.json || {
echo "No changes to package.json" echo "No changes to package.json"
exit 1 exit 1
} }
- name: Get version number from package.json
id: get_version
run: |
VERSION=$(jq -r '.version' package.json)
echo "::set-output name=version::$VERSION"
- name: Extract latest CHANGELOG entry - name: Get version number from package.json
id: changelog id: get_version
run: | run: |
CHANGELOG_CONTENT=$(awk 'BEGIN {print_section=0;} /^## \[/ {if (print_section == 0) {print_section=1;} else {exit;}} print_section {print;}' CHANGELOG.md) VERSION=$(jq -r '.version' package.json)
CHANGELOG_ESCAPED=$(echo "$CHANGELOG_CONTENT" | sed ':a;N;$!ba;s/\n/%0A/g') echo "::set-output name=version::$VERSION"
echo "Extracted latest release notes from CHANGELOG.md:"
echo -e "$CHANGELOG_CONTENT"
echo "::set-output name=content::$CHANGELOG_ESCAPED"
- name: Create GitHub release - name: Extract latest CHANGELOG entry
uses: actions/github-script@v7 id: changelog
with: run: |
github-token: ${{ secrets.GITHUB_TOKEN }} CHANGELOG_CONTENT=$(awk 'BEGIN {print_section=0;} /^## \[/ {if (print_section == 0) {print_section=1;} else {exit;}} print_section {print;}' CHANGELOG.md)
script: | CHANGELOG_ESCAPED=$(echo "$CHANGELOG_CONTENT" | sed ':a;N;$!ba;s/\n/%0A/g')
const changelog = `${{ steps.changelog.outputs.content }}`; echo "Extracted latest release notes from CHANGELOG.md:"
const release = await github.rest.repos.createRelease({ echo -e "$CHANGELOG_CONTENT"
owner: context.repo.owner, echo "::set-output name=content::$CHANGELOG_ESCAPED"
repo: context.repo.repo,
tag_name: `v${{ steps.get_version.outputs.version }}`,
name: `v${{ steps.get_version.outputs.version }}`,
body: changelog,
})
console.log(`Created release ${release.data.html_url}`)
- name: Upload package to GitHub release - name: Create GitHub release
uses: actions/upload-artifact@v4 uses: actions/github-script@v7
with: with:
name: package github-token: ${{ secrets.GITHUB_TOKEN }}
path: . script: |
env: const changelog = `${{ steps.changelog.outputs.content }}`;
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${{ steps.get_version.outputs.version }}`,
name: `v${{ steps.get_version.outputs.version }}`,
body: changelog,
})
console.log(`Created release ${release.data.html_url}`)
- name: Trigger Docker build workflow - name: Upload package to GitHub release
uses: actions/github-script@v7 uses: actions/upload-artifact@v4
with: with:
script: | name: package
github.rest.actions.createWorkflowDispatch({ path: |
owner: context.repo.owner, .
repo: context.repo.repo, !.git
workflow_id: 'docker-build.yaml', env:
ref: 'v${{ steps.get_version.outputs.version }}', GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
})
- name: Trigger Docker build workflow
uses: actions/github-script@v7
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'docker-build.yaml',
ref: 'v${{ steps.get_version.outputs.version }}',
})