-
Notifications
You must be signed in to change notification settings - Fork 10
125 lines (124 loc) · 4.48 KB
/
Copy pathcmo-make-targets.yaml
File metadata and controls
125 lines (124 loc) · 4.48 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
121
122
123
124
125
name: cluster-monitoring-operator make targets
on:
workflow_call:
inputs:
pr-title:
description: Pull request title.
required: true
type: string
pr-body:
description: Pull request body.
required: true
type: string
make-targets:
description: List of make targets to be executed sequentially.
required: true
type: string
secrets:
cloner-app-id:
description: Github ID of cloner app
required: true
cloner-app-private-key:
description: Github private key of cloner app
required: true
pr-app-id:
description: Github ID of PR creation app
required: true
pr-app-private-key:
description: Github private key of PR creation app
required: true
slack-webhook-url:
description: Slack webhook URL to send notification
required: true
env:
USER: 'github-actions[bot]<github-actions[bot]@users.noreply.github.com>'
jobs:
execute-make-targets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
repository: openshift/cluster-monitoring-operator
ref: main
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Execute make targets - ${{ inputs.make-targets }}
run: make ${{ inputs.make-targets }}
- name: Ignore if change is only in jsonnetfile.lock.json
run: |
# Reset jsonnetfile.lock.json if no dependencies were updated.
# grep returns 0 when it matches at least 1 line in the diff output.
if ! git diff --name-only | grep -qv 'jsonnetfile.lock.json'; then
git checkout -- jsonnet/jsonnetfile.lock.json;
fi
- name: Get app token for pull request creation
id: pr
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.pr-app-id }}
private-key: ${{ secrets.pr-app-private-key }}
owner: openshift
- name: Get app token for repository cloning
id: cloner
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.cloner-app-id }}
private-key: ${{ secrets.cloner-app-private-key }}
owner: rhobs
- name: Find branch name
id: branch
run: |
echo sandbox="$(echo ${{ inputs.make-targets }} | sed 's/ /-/g')" >> "$GITHUB_OUTPUT"
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@v8
with:
commit-message: ${{ inputs.pr-title }}
title: ${{ inputs.pr-title }}
body: ${{ inputs.pr-body }}
author: ${{ env.USER }}
committer: ${{ env.USER }}
signoff: true
branch: automated-updates-main-${{ steps.branch.outputs.sandbox }}
delete-branch: true
token: ${{ steps.pr.outputs.token }}
push-to-fork: rhobs/cluster-monitoring-operator
branch-token: ${{ steps.cloner.outputs.token }}
maintainer-can-modify: false
- name: Compose slack message body
id: slack-message
run: |
if [ "${{ steps.create-pr.outputs.pull-request-url }}" == "" ]; then
echo "message=No changes detected." >> "$GITHUB_OUTPUT"
elif [ "${{ steps.create-pr.outputs.pull-request-operation }}" == "none" ]; then
echo "message=PR ${{ steps.create-pr.outputs.pull-request-url }} is ready for review." >> "$GITHUB_OUTPUT"
else
echo "message=PR ${{ steps.create-pr.outputs.pull-request-url }} has been ${{ steps.create-pr.outputs.pull-request-operation }}." >> "$GITHUB_OUTPUT"
fi
- uses: slackapi/slack-github-action@v4
continue-on-error: true
if: success()
with:
webhook: ${{ secrets.slack-webhook-url }}
webhook-type: incoming-webhook
payload: |
{
attachments: [{
color: "good",
text: "${{ github.workflow }}\n${{ steps.slack-message.outputs.message }}\nAction run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}]
}
- uses: slackapi/slack-github-action@v4
continue-on-error: true
if: failure()
with:
webhook: ${{ secrets.slack-webhook-url }}
webhook-type: incoming-webhook
payload: |
{
attachments: [{
color: "danger",
text: "${{ github.workflow }} has failed.\nAction run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}]
}