Skip to content

Commit f0276f7

Browse files
authored
update-project-version: Show project names and versions in PR body and title (when possible) (#20)
* update-project-version: Show project name and version in PR title * update-project-version: Pass a list to subprocess.check_output * update-project-version: Fix an incorrect variable name * update-project-version: Convert lingering bash syntax to Python * update-project-version: Use subprocess.run instead of subprocess.check_output
1 parent a52fd19 commit f0276f7

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

update-project-version/action.yml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,40 @@ runs:
4848
run: python ${{ github.action_path }}/update_version.py ${{ inputs.version-rule }} ${{ inputs.use-dev-suffix == 'true' && '--dev' || '' }}
4949
shell: bash
5050
working-directory: ${{ inputs.project-directory }}
51-
- name: Get changed files
52-
id: get-changed-files
51+
- name: Get PR details
52+
id: get-pr-details
5353
run: |
54-
echo "changed-files<<EOF" >> "$GITHUB_OUTPUT"
55-
# Prefix with "- " to generate a Markdown list.
56-
git diff --name-only | awk '{ print "-", $0 }' >> "$GITHUB_OUTPUT"
57-
echo "EOF" >> "$GITHUB_OUTPUT"
58-
shell: bash
54+
import pathlib, os, subprocess
55+
changed_files = [pathlib.Path(file) for file in subprocess.run(["git", "diff", "--name-only"], capture_output=True, check=True, text=True).stdout.split()]
56+
changed_projects = [file for file in changed_files if file.name == "pyproject.toml"]
57+
project_info = {}
58+
for project in changed_projects:
59+
name, version = subprocess.run(["poetry", "version", "-C", str(project.parent)], capture_output=True, check=True, text=True).stdout.split()
60+
project_info[project] = {"name": name, "version": version}
61+
if len(changed_projects) == 1:
62+
title = "chore: Update project {} to v{}".format(project_info[changed_projects[0]]["name"], project_info[changed_projects[0]]["version"])
63+
else:
64+
title = "chore: Update project versions"
65+
base_branch = "${{ steps.set-vars.outputs.base-branch }}"
66+
if base_branch not in ["main", "master"]:
67+
title = f"[{base_branch}] {title}"
68+
with open(os.environ["GITHUB_OUTPUT"], "a") as output:
69+
print(f"title={title}", file=output)
70+
print("project-table<<EOF", file=output)
71+
print("| Project | Version | Path |", file=output)
72+
print("|---------|---------|------|", file=output)
73+
for project in changed_projects:
74+
print(f"| {project_info[project]['name']} | {project_info[project]['version']} | {project} |", file=output)
75+
print("EOF", file=output)
76+
shell: python
5977
- name: Create pull request
6078
if: inputs.create-pull-request == 'true'
6179
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
6280
with:
6381
base: ${{ steps.set-vars.outputs.base-branch }}
6482
branch: ${{ steps.set-vars.outputs.branch-name }}
65-
commit-message: "chore: Update project version - ${{ steps.set-vars.outputs.base-branch }}"
66-
title: "chore: Update project version - ${{ steps.set-vars.outputs.base-branch }}"
83+
commit-message: ${{ steps.get-pr-details.outputs.title }}
84+
title: ${{ steps.get-pr-details.outputs.title }}
6785
token: ${{ inputs.token }}
6886
# The workflow log currently points to the run, not the specific job
6987
# within that run. Linking to a specific job requires the numeric job id,
@@ -72,6 +90,6 @@ runs:
7290
body: |
7391
This PR updates the versions of the following Python projects:
7492
75-
${{ steps.get-changed-files.outputs.changed-files }}
93+
${{ steps.get-pr-details.outputs.project-table }}
7694
7795
This PR was generated by [ni/python-actions/update-project-version](https://github.com/ni/python-actions/). View the [workflow log](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).

0 commit comments

Comments
 (0)