Skip to content

Check git version correctly #110

Check git version correctly

Check git version correctly #110

Workflow file for this run

name: Check Version and Comment on PR
on:
pull_request_target:
branches:
- main
paths-ignore:
- '**/README.md'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
version_check:
name: Check pyproject.toml version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 14
- run: |
npm install semver
npm install toml
- name: Fetch main branch
run: |
git remote add jdoiro3_main https://github.com/jdoiro3/mkdocs-multirepo-plugin
git fetch --no-tags jdoiro3_main main:jdoiro3_main
- name: Get Old pyproject.toml and Hashes of CHANGELOG.md
run: |
git show jdoiro3_main:pyproject.toml > old_pyproject.toml
main_changelog=$(git show jdoiro3_main:CHANGELOG.md | git hash-object --stdin)
curr_changelog=$(git show ${{ github.head_ref }}:CHANGELOG.md | git hash-object --stdin)
echo "main_changelog=${main_changelog}" >> $GITHUB_ENV
echo "curr_changelog=$curr_changelog" >> $GITHUB_ENV
- name: Version Check
uses: actions/github-script@v6
id: comment-body
with:
script: |
const toml = require('toml')
const fs = require('fs').promises
const semver = require('semver')
var pyproject = toml.parse(await fs.readFile('pyproject.toml', 'utf8'))
var old_pyproject = toml.parse(await fs.readFile('old_pyproject.toml', 'utf8'))
var msg_body = ""
if (semver.gte(old_pyproject.tool.poetry.version, pyproject.tool.poetry.version)) {
msg_body = (
`Update the version in [pyproject.toml](https://github.com/${{ github.event.pull_request.head.repo.full_name }}/blob/${{ github.head_ref }}/pyproject.toml) if you want this PR to generate a new release (main is ${old_pyproject.tool.poetry.version} >= ${pyproject.tool.poetry.version}).`
)
} else {
msg_body = "Version has been updated in pyproject.toml."
}
if ("${{ env.curr_changelog }}" === "${{ env.main_changelog }}") {
msg_body += ` In addition, please update the [CHANGELOG.md](https://github.com/${{ github.event.pull_request.head.repo.full_name }}/blob/${{ github.head_ref }}/CHANGELOG.md).`
}
return msg_body
result-encoding: string
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: "## Version Number Check"
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Version Number Check
${{steps.comment-body.outputs.result}}
edit-mode: replace