-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
102 lines (99 loc) · 5.36 KB
/
action.yml
File metadata and controls
102 lines (99 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Update project version
description: Update the version of a Python project and create a pull request.
inputs:
project-directory:
description: Path to the directory containing pyproject.toml.
default: ${{ github.workspace }}
branch-prefix:
description: The branch prefix to use when creating pull requests.
default: users/build/
create-pull-request:
description: >
Specifies whether to create a pull request. Set this to false to update
the project version without creating a pull request.
default: true
token:
description: >
GitHub token to use to create the pull request. The default GITHUB_TOKEN
cannot trigger PR workflows (i.e., it will not run PR status checks). You
can use this input to specify a PAT that is saved in a repo/org secret.
default: ${{ github.token }}
version-rule:
description: >
Specifies the rule for how to update the version number, such as "major",
"minor", or "patch". See https://python-poetry.org/docs/cli/#version for
the list of rules and their behavior.
default: patch
use-dev-suffix:
description: Specifies whether to use development versions like "1.0.0.dev0".
default: true
runs:
using: composite
steps:
- name: Set variables
id: set-vars
run: |
# For release events, github.ref_name is the release tag (e.g. 1.0.0) and
# github.event.release.target_commitish is the branch/tag/commit that the
# tag was created from (e.g. main).
#
# For workflow_dispatch events, github.ref_name is the branch/tag/commit
# that the workflow was dispatched on.
base_branch="${{ github.event_name == 'release' && github.event.release.target_commitish || github.ref_name }}"
base_branch_no_slashes=$(echo $base_branch | tr '/' '-')
echo "base-branch=$base_branch" >> "$GITHUB_OUTPUT"
echo "branch-name=${{ inputs.branch-prefix }}update-project-version-$base_branch_no_slashes" >> "$GITHUB_OUTPUT"
shell: bash
- name: Update the version in pyproject.toml
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 PR details
id: get-pr-details
run: |
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@98357b18bf14b5342f975ff684046ec3b2a07725 # v8.0.0
env:
action-url: https://github.com/${{ github.action_repository }}/tree/${{ github.action_ref }}/update-project-version
with:
base: ${{ steps.set-vars.outputs.base-branch }}
branch: ${{ steps.set-vars.outputs.branch-name }}
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,
# which is not available in the github context.
# https://stackoverflow.com/questions/71240338/obtain-job-id-from-a-workflow-run-using-contexts
body: |
This PR updates the versions of the following Python projects:
${{ steps.get-pr-details.outputs.project-table }}
If the checks for this pull request appear to hang, you can work around this by closing and re-opening the PR. See
[ni/python-actions/update-project-version >> Inputs >> token](${{ env.action-url }}#token) and
[create-pull-request >> Triggering further workflow runs](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs)
for more details.
This PR was generated by [ni/python-actions/update-project-version](${{ env.action-url }}). View the [workflow log](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).