Skip to content

Commit d9e4284

Browse files
Copilotrjaegers
andauthored
ci: replace create-pull-request with gh cli in dependency updater
Agent-Logs-Url: https://github.com/philips-software/amp-devcontainer/sessions/9bb088b8-f6bb-4cf9-b9d7-fa3fc465557b Co-authored-by: rjaegers <45816308+rjaegers@users.noreply.github.com>
1 parent 06446c4 commit d9e4284

1 file changed

Lines changed: 61 additions & 23 deletions

File tree

.github/workflows/update-dependencies.yml

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
# set-up correctly.
2222
container: ghcr.io/philips-software/amp-devcontainer-${{ matrix.flavor }}:edge
2323
permissions:
24-
contents: write # is needed by peter-evans/create-pull-request to create branches and push commits
25-
pull-requests: write # is needed by peter-evans/create-pull-request to create a PR
24+
contents: write # is needed by gh cli to create branches and push commits
25+
pull-requests: write # is needed by gh cli to create a PR
2626
steps:
2727
- uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
2828
with:
@@ -40,27 +40,46 @@ jobs:
4040
with:
4141
app-id: ${{ vars.FOREST_RELEASER_APP_ID }}
4242
private-key: ${{ secrets.FOREST_RELEASER_APP_PRIVATE_KEY }}
43-
- uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
43+
- name: Create pull request
4444
if: github.event_name != 'pull_request'
45-
with:
46-
commit-message: "Update ${{ join(fromJson(steps.update-packages.outputs.updated-dependencies), ', ') }}"
47-
branch: feature/amp-devcontainer-${{ matrix.flavor }}/update-apt-packages
48-
title: "chore(deps, ${{ matrix.flavor }}): update ${{ join(fromJson(steps.update-packages.outputs.updated-dependencies), ', ') }}"
49-
labels: dependencies,apt
50-
token: ${{ steps.token.outputs.token }}
51-
sign-commits: true
45+
env:
46+
BRANCH: feature/amp-devcontainer-${{ matrix.flavor }}/update-apt-packages
47+
COMMIT_MESSAGE: Update ${{ join(fromJson(steps.update-packages.outputs.updated-dependencies), ', ') }}
48+
GH_TOKEN: ${{ steps.token.outputs.token }}
49+
TITLE: "chore(deps, ${{ matrix.flavor }}): update ${{ join(fromJson(steps.update-packages.outputs.updated-dependencies), ', ') }}"
50+
run: |
51+
if [[ -z "$(git status --porcelain)" ]]; then
52+
echo No changes detected
53+
exit 0
54+
fi
55+
56+
git config user.name github-actions[bot]
57+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
58+
gh auth setup-git
59+
60+
git checkout -B "${BRANCH}"
61+
git add .
62+
git commit -m "${COMMIT_MESSAGE}"
63+
git push --force-with-lease origin "${BRANCH}"
64+
65+
pr_number="$(gh pr list --head "${BRANCH}" --state open --json number --jq '.[0].number')"
66+
if [[ -n "${pr_number}" ]]; then
67+
gh pr edit "${pr_number}" --title "${TITLE}" --add-label dependencies --add-label apt
68+
else
69+
gh pr create --head "${BRANCH}" --title "${TITLE}" --body "${COMMIT_MESSAGE}" --label dependencies --label apt
70+
fi
5271
5372
update-vscode-extensions:
5473
name: ${{ github.event_name == 'pull_request' && '🧪' || '' }} Extensions (🍨 ${{ matrix.flavor }}, ${{ matrix.file }})
5574
runs-on: ubuntu-latest
5675
strategy:
5776
fail-fast: false
5877
matrix:
59-
flavor: ["cpp", "rust"]
60-
file: ["devcontainer-metadata.json", "devcontainer.json"]
78+
flavor: [cpp, rust]
79+
file: [devcontainer-metadata.json, devcontainer.json]
6180
permissions:
62-
contents: write # is needed by peter-evans/create-pull-request to create branches and push commits
63-
pull-requests: write # is needed by peter-evans/create-pull-request to create a PR
81+
contents: write # is needed by gh cli to create branches and push commits
82+
pull-requests: write # is needed by gh cli to create a PR
6483
steps:
6584
- uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
6685
with:
@@ -88,13 +107,32 @@ jobs:
88107
with:
89108
app-id: ${{ vars.FOREST_RELEASER_APP_ID }}
90109
private-key: ${{ secrets.FOREST_RELEASER_APP_PRIVATE_KEY }}
91-
- uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
110+
- name: Create pull request
92111
if: github.event_name != 'pull_request'
93-
with:
94-
commit-message: "Update ${{ join(fromJson(steps.update-extensions.outputs.updated-dependencies), ', ') }} in ${{ matrix.file }}"
95-
branch: feature/amp-devcontainer-${{ matrix.flavor }}/update-vscode-extensions-${{ matrix.file }}
96-
body-path: ${{ runner.temp }}/pull-request-body.md
97-
title: "chore(deps, ${{ matrix.flavor }}): update ${{ join(fromJson(steps.update-extensions.outputs.updated-dependencies), ', ') }} in ${{ matrix.file }}"
98-
labels: dependencies,vscode-extensions
99-
token: ${{ steps.token.outputs.token }}
100-
sign-commits: true
112+
env:
113+
BODY_PATH: ${{ runner.temp }}/pull-request-body.md
114+
BRANCH: feature/amp-devcontainer-${{ matrix.flavor }}/update-vscode-extensions-${{ matrix.file }}
115+
COMMIT_MESSAGE: Update ${{ join(fromJson(steps.update-extensions.outputs.updated-dependencies), ', ') }} in ${{ matrix.file }}
116+
GH_TOKEN: ${{ steps.token.outputs.token }}
117+
TITLE: "chore(deps, ${{ matrix.flavor }}): update ${{ join(fromJson(steps.update-extensions.outputs.updated-dependencies), ', ') }} in ${{ matrix.file }}"
118+
run: |
119+
if [[ -z "$(git status --porcelain)" ]]; then
120+
echo No changes detected
121+
exit 0
122+
fi
123+
124+
git config user.name github-actions[bot]
125+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
126+
gh auth setup-git
127+
128+
git checkout -B "${BRANCH}"
129+
git add .
130+
git commit -m "${COMMIT_MESSAGE}"
131+
git push --force-with-lease origin "${BRANCH}"
132+
133+
pr_number="$(gh pr list --head "${BRANCH}" --state open --json number --jq '.[0].number')"
134+
if [[ -n "${pr_number}" ]]; then
135+
gh pr edit "${pr_number}" --title "${TITLE}" --body-file "${BODY_PATH}" --add-label dependencies --add-label vscode-extensions
136+
else
137+
gh pr create --head "${BRANCH}" --title "${TITLE}" --body-file "${BODY_PATH}" --label dependencies --label vscode-extensions
138+
fi

0 commit comments

Comments
 (0)