Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions update-project-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,40 @@ runs:
run: python ${{ github.action_path }}/update_version.py ${{ inputs.version-rule }} ${{ inputs.use-dev-suffix == 'true' && '--dev' || '' }}
shell: bash
working-directory: ${{ inputs.project-directory }}
- name: Get changed files
id: get-changed-files
- name: Get PR details
id: get-pr-details
run: |
echo "changed-files<<EOF" >> "$GITHUB_OUTPUT"
# Prefix with "- " to generate a Markdown list.
git diff --name-only | awk '{ print "-", $0 }' >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
shell: bash
import pathlib, os, subprocess
changed_files = [pathlib.Path(file) for file in subprocess.run(["git", "diff", "--name-only"], capture_output=True, check=True, text=True).stdout.split()]
changed_projects = [file for file in changed_files if file.name == "pyproject.toml"]
project_info = {}
for project in changed_projects:
name, version = subprocess.run(["poetry", "version", "-C", str(project.parent)], capture_output=True, check=True, text=True).stdout.split()
project_info[project] = {"name": name, "version": version}
if len(changed_projects) == 1:
title = "chore: Update project {} to v{}".format(project_info[changed_projects[0]]["name"], project_info[changed_projects[0]]["version"])
else:
title = "chore: Update project versions"
base_branch = "${{ steps.set-vars.outputs.base-branch }}"
if base_branch not in ["main", "master"]:
title = f"[{base_branch}] {title}"
with open(os.environ["GITHUB_OUTPUT"], "a") as output:
print(f"title={title}", file=output)
print("project-table<<EOF", file=output)
print("| Project | Version | Path |", file=output)
print("|---------|---------|------|", file=output)
for project in changed_projects:
print(f"| {project_info[project]['name']} | {project_info[project]['version']} | {project} |", file=output)
print("EOF", file=output)
shell: python
- name: Create pull request
if: inputs.create-pull-request == 'true'
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
with:
base: ${{ steps.set-vars.outputs.base-branch }}
branch: ${{ steps.set-vars.outputs.branch-name }}
commit-message: "chore: Update project version - ${{ steps.set-vars.outputs.base-branch }}"
title: "chore: Update project version - ${{ steps.set-vars.outputs.base-branch }}"
commit-message: ${{ steps.get-pr-details.outputs.title }}
title: ${{ steps.get-pr-details.outputs.title }}
token: ${{ inputs.token }}
# The workflow log currently points to the run, not the specific job
# within that run. Linking to a specific job requires the numeric job id,
Expand All @@ -72,6 +90,6 @@ runs:
body: |
This PR updates the versions of the following Python projects:

${{ steps.get-changed-files.outputs.changed-files }}
${{ steps.get-pr-details.outputs.project-table }}

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 }}).
Loading