Skip to content

Commit dfaffe7

Browse files
committed
Update gha workflows to fix .changelog logic
Trigger k8s after a .changelog entry was for dependabot's PRs
1 parent 636cf36 commit dfaffe7

File tree

3 files changed

+73
-50
lines changed

3 files changed

+73
-50
lines changed

.github/workflows/.dependabot_misc.yml

-46
This file was deleted.

.github/workflows/changelog.yml

+72-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,90 @@ name: Changelog Entry
44

55
on:
66
pull_request:
7-
types: [opened, synchronize, labeled]
7+
types: [opened, synchronize, labeled, reopened]
88
# Runs on PRs to main and all release branches
99
branches:
1010
- main
1111

12+
permissions:
13+
pull-requests: write
14+
contents: write
15+
1216
jobs:
17+
generate-release-note:
18+
if: github.actor == 'dependabot[bot]'
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
23+
with:
24+
fetch-depth: 0
25+
ref: ${{ github.event.pull_request.head.ref }}
26+
- name: Generate .changelog entry
27+
env:
28+
PR_NUMBER: ${{ github.event.pull_request.number }}
29+
PR_TITLE: ${{ github.event.pull_request.title }}
30+
PR_BODY: ${{ github.event.pull_request.body_text }}
31+
run: |
32+
FIRST_COMMIT=$(git log -10 --pretty=format:%H origin/main..HEAD | tail -1)
33+
FIRST_COMMIT_BODY=$(git log -1 --pretty=format:%B $FIRST_COMMIT)
34+
mkdir -p .changelog
35+
echo "backticksrelease-note:enhancement" > .changelog/$PR_NUMBER.txt
36+
echo "ci/dependabot: $PR_TITLE" >> .changelog/$PR_NUMBER.txt
37+
echo "" >> .changelog/$PR_NUMBER.txt
38+
echo "$FIRST_COMMIT_BODY" >> .changelog/$PR_NUMBER.txt
39+
echo "backticks" >> .changelog/$PR_NUMBER.txt
40+
sed -i 's/backticks/```/g' .changelog/$PR_NUMBER.txt
41+
- name: Commit and Push
42+
env:
43+
GIT_USER: ${{ secrets.GIT_USER }}
44+
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
45+
run: |
46+
git branch
47+
echo "---"
48+
git log -1
49+
echo "---"
50+
git config --local user.email "dependabot[bot]@users.noreply.github.com"
51+
git config --local user.name "dependabot[bot]"
52+
git add .changelog
53+
git commit --amend --no-edit
54+
echo "---"
55+
git log -1
56+
git push --force "https://x-access-token:$GITHUB_TOKEN@github.com/${{ github.repository }}.git" HEAD:${{ github.event.pull_request.head.ref }}
1357
# checks that a .changelog entry is present for a PR
58+
changelog-check-dpbot:
59+
runs-on: ubuntu-latest
60+
needs: [generate-release-note]
61+
steps:
62+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
63+
with:
64+
# ref: ${{ github.event.pull_request.head.sha }}
65+
ref: ${{ github.event.pull_request.head.ref }}
66+
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
67+
- name: Check for changelog entry in diff
68+
run: |
69+
# check if there is a diff in the .changelog directory
70+
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- .changelog/${{ github.event.pull_request.number }}.txt)
71+
72+
# If we do not find a file in .changelog/, we fail the check
73+
if [ -z "$changelog_files" ]; then
74+
# Fail status check when no .changelog entry was found on the PR
75+
echo "Did not find a .changelog entry and the 'pr/no-changelog' label was not applied."
76+
exit 1
77+
else
78+
echo "Found .changelog entry in PR!"
79+
fi
80+
- uses: ./.github/workflows/k8s.yml
81+
name: Trigger k8s tests
1482
changelog-check:
1583
# If there a `pr/no-changelog` label we ignore this check
16-
if: "!contains(github.event.pull_request.labels.*.name, 'pr/no-changelog') || github.event.pull_request.user.login == 'dependabot'"
84+
if: "!contains(github.event.pull_request.labels.*.name, 'pr/no-changelog')"
1785
runs-on: ubuntu-latest
18-
1986
steps:
2087
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
2188
with:
22-
ref: ${{ github.event.pull_request.head.sha }}
89+
# ref: ${{ github.event.pull_request.head.sha }}
90+
ref: ${{ github.event.pull_request.head.ref }}
2391
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
2492
- name: Check for changelog entry in diff
2593
run: |

.github/workflows/k8s.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: k8s
22
on:
33
pull_request:
44
workflow_dispatch:
5+
workflow_call:
56

67
env:
78
GO_VERSION: "1.22.2"

0 commit comments

Comments
 (0)