build-release.yml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. name: Release
  2. on:
  3. push:
  4. branches:
  5. - main # or whatever branch you want to use
  6. jobs:
  7. release:
  8. runs-on: ubuntu-latest
  9. steps:
  10. - name: Checkout repository
  11. uses: actions/checkout@v4
  12. - name: Check for changes in package.json
  13. run: |
  14. git diff --cached --diff-filter=d package.json || {
  15. echo "No changes to package.json"
  16. exit 1
  17. }
  18. - name: Get version number from package.json
  19. id: get_version
  20. run: |
  21. VERSION=$(jq -r '.version' package.json)
  22. echo "::set-output name=version::$VERSION"
  23. - name: Extract latest CHANGELOG entry
  24. id: changelog
  25. run: |
  26. CHANGELOG_CONTENT=$(awk 'BEGIN {print_section=0;} /^## \[/ {if (print_section == 0) {print_section=1;} else {exit;}} print_section {print;}' CHANGELOG.md)
  27. CHANGELOG_ESCAPED=$(echo "$CHANGELOG_CONTENT" | sed ':a;N;$!ba;s/\n/%0A/g')
  28. echo "Extracted latest release notes from CHANGELOG.md:"
  29. echo -e "$CHANGELOG_CONTENT"
  30. echo "::set-output name=content::$CHANGELOG_ESCAPED"
  31. - name: Create GitHub release
  32. uses: actions/github-script@v7
  33. with:
  34. github-token: ${{ secrets.GITHUB_TOKEN }}
  35. script: |
  36. const changelog = `${{ steps.changelog.outputs.content }}`;
  37. const release = await github.rest.repos.createRelease({
  38. owner: context.repo.owner,
  39. repo: context.repo.repo,
  40. tag_name: `v${{ steps.get_version.outputs.version }}`,
  41. name: `v${{ steps.get_version.outputs.version }}`,
  42. body: changelog,
  43. })
  44. console.log(`Created release ${release.data.html_url}`)
  45. - name: Upload package to GitHub release
  46. uses: actions/upload-artifact@v4
  47. with:
  48. name: package
  49. path: |
  50. .
  51. !.git
  52. env:
  53. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  54. - name: Trigger Docker build workflow
  55. uses: actions/github-script@v7
  56. with:
  57. script: |
  58. github.rest.actions.createWorkflowDispatch({
  59. owner: context.repo.owner,
  60. repo: context.repo.repo,
  61. workflow_id: 'docker-build.yaml',
  62. ref: 'v${{ steps.get_version.outputs.version }}',
  63. })