Enhance PR messaging for checks #364
Workflow file for this run
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: Check version | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
concurrency: | |
group: version-${{ github.head_ref }} | |
cancel-in-progress: true | |
jobs: | |
check-version: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v1.3.0 | |
with: | |
reviewdog_version: v0.17.2 | |
- uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 | |
id: generate-token | |
with: | |
app_id: ${{ secrets.APP_ID }} | |
private_key: ${{ secrets.APP_PRIVATE_KEY }} | |
- name: Checkout repository | |
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | |
with: | |
ref: master | |
- name: Master version | |
id: master_version | |
run: | | |
#echo version=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}') >> $GITHUB_OUTPUT | |
echo version=$(grep -o 'version = ".*"' build.gradle.kts | grep -o '[0-9\.]*') >> $GITHUB_OUTPUT | |
- name: Checkout repository | |
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | |
- name: New version | |
id: new_version | |
run: | | |
#echo version=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}') >> $GITHUB_OUTPUT | |
echo version=$(grep -o 'version = ".*"' build.gradle.kts | grep -o '[0-9\.]*') >> $GITHUB_OUTPUT | |
- name: test version | |
id: version_test | |
run: | | |
compare_versions() { | |
IFS='.' read -r -a new_arr <<< $1 | |
IFS='.' read -r -a master_arr <<< $2 | |
local i | |
for ((i = 0; i < 3; i++)); do | |
if [ ${new_arr[$i]} -gt ${master_arr[$i]} ]; then | |
return 0 | |
elif [ ${new_arr[$i]} -lt ${master_arr[$i]} ]; then | |
return 1 | |
fi | |
done | |
return 2 | |
} | |
compare_versions "${{ steps.new_version.outputs.version }}" "${{ steps.master_version.outputs.version }}" && echo status="ok" >> $GITHUB_OUTPUT || echo status="notok" >> $GITHUB_OUTPUT | |
- name: version is correct | |
if: ${{ steps.version_test.outputs.status }} == "ok" | |
run: echo "New version ${{ steps.new_version.outputs.version }} is OK" | |
- name: version is incorrect, creating suggestion | |
if: ${{ steps.version_test.outputs.status }} == "notok" | |
run: | | |
IFS='.' read -r -a array <<< "${{ steps.new_version.outputs.version }}" | |
new_version="${array[0]}.${array[1]}.$((array[2]+1))" | |
sed -i "s/version = \".*\"/version = \"$new_version\"/" build.gradle.kts | |
- name: version is incorrect, posting suggestion | |
if: ${{ steps.version_test.outputs.status }} == "notok" | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ steps.generate-token.outputs.token }} | |
run: | | |
git diff | reviewdog -f=diff -reporter=github-pr-review | |
- name: version is incorrect, reporting | |
if: ${{ steps.version_test.outputs.status }} == "notok" | |
run: | | |
echo "New version ${{ steps.new_version.outputs.version }} is NOT OK" | |
exit 1 |