name: publish on: workflow_dispatch: inputs: version-change: description: Version part required: true type: choice options: - PATCH - MINOR permissions: contents: write jobs: publish: runs-on: ubuntu-latest env: GITHUB_TOKEN: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }} VERSION_CHANGE: ${{ github.event.inputs.version-change }} RELEASE_CANDIDATE: ${{ github.event.inputs.release-candidate }} VERSION_FILE: src/Version.php CHANGELOG_FILE: CHANGELOG.md steps: - uses: actions/checkout@v3 with: token: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }} - run: | CHANGELOG=$(cat $CHANGELOG_FILE | sed -e '/^## */,$d'); MAJOR=$(cat $VERSION_FILE | grep "const MAJOR" | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g'); MINOR=$(cat $VERSION_FILE | grep "const MINOR" | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g'); PATCH=$(cat $VERSION_FILE | grep "const PATCH" | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g'); LAST_TAG="v$MAJOR.$MINOR.$PATCH"; if [ "$VERSION_CHANGE" = "MINOR" ] then MINOR=$((MINOR+1)); PATCH=0; fi; if [ "$VERSION_CHANGE" = "PATCH" ] then PATCH=$((PATCH+1)); fi; echo "> $VERSION_FILE.tmp mv $VERSION_FILE.tmp $VERSION_FILE; git add $VERSION_FILE; echo "## $MAJOR.$MINOR.$PATCH" >> $CHANGELOG_FILE.tmp cat $CHANGELOG_FILE >> $CHANGELOG_FILE.tmp mv $CHANGELOG_FILE.tmp $CHANGELOG_FILE; git add $CHANGELOG_FILE; git config --global user.email "robot@umbrella"; git config --global user.name "robot"; git commit -m "Release v$MAJOR.$MINOR.$PATCH"; TAG="v$MAJOR.$MINOR.$PATCH"; git tag $TAG git push --tags && git push CHANGELOG="$CHANGELOG Full Changelog: [$LAST_TAG...$TAG](https://github.com/${{ github.repository }}/compare/$LAST_TAG...$TAG)" gh release create $TAG -t "$TAG" --notes "$CHANGELOG"