publish.yml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. name: publish
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. version-change:
  6. description: Version part
  7. required: true
  8. type: choice
  9. options:
  10. - PATCH
  11. - MINOR
  12. permissions:
  13. contents: write
  14. jobs:
  15. publish:
  16. runs-on: ubuntu-latest
  17. env:
  18. GITHUB_TOKEN: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}
  19. VERSION_CHANGE: ${{ github.event.inputs.version-change }}
  20. RELEASE_CANDIDATE: ${{ github.event.inputs.release-candidate }}
  21. VERSION_FILE: src/Version.php
  22. CHANGELOG_FILE: CHANGELOG.md
  23. steps:
  24. - uses: actions/checkout@v3
  25. with:
  26. token: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}
  27. - run: |
  28. CHANGELOG=$(cat $CHANGELOG_FILE | sed -e '/^## */,$d');
  29. MAJOR=$(cat $VERSION_FILE | grep "const MAJOR" | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
  30. MINOR=$(cat $VERSION_FILE | grep "const MINOR" | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
  31. PATCH=$(cat $VERSION_FILE | grep "const PATCH" | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
  32. LAST_TAG="v$MAJOR.$MINOR.$PATCH";
  33. if [ "$VERSION_CHANGE" = "MINOR" ]
  34. then
  35. MINOR=$((MINOR+1));
  36. PATCH=0;
  37. fi;
  38. if [ "$VERSION_CHANGE" = "PATCH" ]
  39. then
  40. PATCH=$((PATCH+1));
  41. fi;
  42. echo "<?php
  43. const MAJOR = \"$MAJOR\";
  44. const MINOR = \"$MINOR\";
  45. const PATCH = \"$PATCH\";
  46. " >> $VERSION_FILE.tmp
  47. mv $VERSION_FILE.tmp $VERSION_FILE;
  48. git add $VERSION_FILE;
  49. echo "## $MAJOR.$MINOR.$PATCH" >> $CHANGELOG_FILE.tmp
  50. cat $CHANGELOG_FILE >> $CHANGELOG_FILE.tmp
  51. mv $CHANGELOG_FILE.tmp $CHANGELOG_FILE;
  52. git add $CHANGELOG_FILE;
  53. git config --global user.email "robot@umbrella";
  54. git config --global user.name "robot";
  55. git commit -m "Release v$MAJOR.$MINOR.$PATCH";
  56. TAG="v$MAJOR.$MINOR.$PATCH";
  57. git tag $TAG
  58. git push --tags && git push
  59. CHANGELOG="$CHANGELOG
  60. Full Changelog: [$LAST_TAG...$TAG](https://github.com/${{ github.repository }}/compare/$LAST_TAG...$TAG)"
  61. gh release create $TAG -t "$TAG" --notes "$CHANGELOG"