Repository navigation
120 lines (108 loc) · 4.94 KB
/
Copy pathlinked-csharp-pr.yml
File metadata and controls
120 lines (108 loc) · 4.94 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: C# PR
# A pull request that changes the Python classes raises a linked DRAFT pull request in the repository that owns the C# classes.
# It never raises anything for a push, so the weekly generation (a push to develop) cannot start it.
#
# The comment it leaves on the Python PR links the draft. A Python PR is only ready once its C# PR is merged: the "C# alignment" job of
# pr-checks.yml fails until then, and is re-run by hand after the merge. Closing the Python PR is handled by linked-csharp-pr-close.yml.
#
# Where C# pull requests may be raised is listed in Converted-repositories.txt. The GitHub App token is made only for the repositories the
# change touches, which are always listed there.
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'src/bhom_schema/**'
workflow_dispatch:
inputs:
pr_number:
description: Number of the Python pull request
required: true
type: string
dry_run:
description: List what would be done, change nothing (the App token is still made, which proves the installation)
type: boolean
default: true
permissions:
contents: read
# A newer push cancels the older run for the same pull request; closing the pull request cancels a run in progress
concurrency:
group: linked-csharp-pr-${{ github.event.pull_request.number || inputs.pr_number }}
cancel-in-progress: true
jobs:
linked:
name: Raise or update draft
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
# The repository itself, only to reach the shared action below
- uses: actions/checkout@v4
- name: Find the pull request and the C# repositories it touches
id: ctx
uses: ./.github/actions/linked-pr-context
with:
pr-number: ${{ inputs.pr_number }}
# A token for the repositories the change touches only, valid for about an hour. It is made on a dry run too, which proves the App is installed.
- name: Make a token for the C# repositories touched
id: token
if: steps.ctx.outputs.raise == 'true'
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.BHOM_APP_ID }}
private-key: ${{ secrets.BHOM_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ steps.ctx.outputs.names }}
- name: Clone the C# repositories
if: steps.ctx.outputs.raise == 'true'
shell: bash
env:
PY2CS_CSHARP_TOKEN: ${{ steps.token.outputs.token }}
REPOS: ${{ steps.ctx.outputs.repos }}
run: |
header="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$PY2CS_CSHARP_TOKEN" | base64 -w0)"
echo "::add-mask::$header"
for repo in $(echo "$REPOS" | jq -r '.[]'); do
git -c "http.extraheader=$header" clone --depth 1 --quiet "https://github.com/$repo.git" "csharp/${repo#*/}"
done
- uses: actions/setup-dotnet@v4
if: steps.ctx.outputs.raise == 'true'
with:
dotnet-version: '8.0.x'
- name: Build the C# patcher
if: steps.ctx.outputs.raise == 'true'
run: dotnet build head/.ci/generation/PythonSchemaGeneration.Patcher/PythonSchemaGeneration.Patcher.csproj -c Release --nologo
- name: Plan the C# changes
if: steps.ctx.outputs.raise == 'true'
shell: bash
env:
PYTHONPATH: head/.ci/generation
PY2CS_PATCHER: head/.ci/generation/PythonSchemaGeneration.Patcher/bin/Release/net8.0/PythonSchemaGeneration.Patcher.dll
REPOS: ${{ steps.ctx.outputs.repos }}
run: |
for repo in $(echo "$REPOS" | jq -r '.[]'); do
python -m py2cs plan \
--base-root base/src/bhom_schema --head-root head/src/bhom_schema \
--clones-parent csharp --allowed-repos base/Converted-repositories.txt \
--only-repo "$repo" \
--python-pr "${{ github.repository }}#${{ steps.ctx.outputs.number }}" \
--out "plan/${repo#*/}"
done
# The tokens are passed to this step only, through the environment, and are never printed
- name: Push the branch and open or update the draft pull request
if: steps.ctx.outputs.raise == 'true'
shell: bash
env:
PYTHONPATH: head/.ci/generation
PY2CS_CSHARP_TOKEN: ${{ steps.token.outputs.token }}
PY2CS_PYTHON_TOKEN: ${{ github.token }}
DRY_RUN: ${{ inputs.dry_run }}
REPOS: ${{ steps.ctx.outputs.repos }}
run: |
flags=""
if [ "$DRY_RUN" = "true" ]; then flags="--dry-run"; fi
for repo in $(echo "$REPOS" | jq -r '.[]'); do
python -m py2cs pr --plan-dir "plan/${repo#*/}" --repo "$repo" \
--python-repo "${{ github.repository }}" --python-pr "${{ steps.ctx.outputs.number }}" \
--python-url "${{ steps.ctx.outputs.url }}" $flags
done