-
Notifications
You must be signed in to change notification settings - Fork 26
108 lines (94 loc) · 3.97 KB
/
generate-catalog-pr.yml
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
name: Generate Catalog PR
on:
workflow_dispatch:
inputs:
appName:
description: "NR1 Nerdpack Name"
required: true
version:
description: "Version to update"
required: true
ref:
description: "Commit SHA to update the submodule to"
required: true
user:
description: "User who initiated the deployment"
required: true
action:
description: "Action to take with submodule. Possible values: add, update"
required: true
default: "update"
url:
description: "If action == `add`, must supply URL of repo"
required: false
env:
GIT_AUTHOR_NAME: "nr-opensource-bot"
GIT_AUTHOR_EMAIL: "opensource+bot@newrelic.com"
GIT_COMMITTER_NAME: "nr-opensource-bot"
GIT_COMMITTER_EMAIL: "opensource+bot@newrelic.com"
jobs:
job-check-workflow-dispatch-inputs:
runs-on: ubuntu-latest
steps:
- run: |
echo "appName: ${{ github.event.inputs.appName }}"
echo "version: ${{ github.event.inputs.version }}"
echo "ref: ${{ github.event.inputs.ref }}"
echo "user: ${{ github.event.inputs.user }}"
echo "action: ${{ github.event.inputs.action }}"
echo "url: ${{ github.event.inputs.url }}"
job-create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
# Create a new branch, Update submodule to the input ref and commit
- name: Add/Update submodule
run: |
git config user.email "${{ env.GIT_AUTHOR_EMAIL }}"
git config user.name "${{ env.GIT_AUTHOR_NAME }}"
# Create branch
# git checkout -b ${{ github.event.inputs.appName }}/${{ github.event.inputs.version }}
# Add / Update submodule
## If adding, need to `git submodule add` to get the submodule into .gitmodules
if [[ "${{ github.event.inputs.action }}" == "add" ]]; then
git submodule add ${{ github.event.inputs.url }} apps/${{ github.event.inputs.appName }}
fi
## Now checkout the ref -- this step is the same regardless of add/update
cd apps/${{ github.event.inputs.appName }}
git checkout ${{ github.event.inputs.ref }}
cd ../..
# Commit back to branch
git add apps/${{ github.event.inputs.appName }}
## Variable commit message
if [[ "${{ github.event.inputs.action }}" == "add" ]]; then
git commit -m 'feat: Add ${{ github.event.inputs.appName }} at version ${{ github.event.inputs.version }}'
echo "title=feat: Add ${{ github.event.inputs.appName }} at version ${{ github.event.inputs.version }}" >> $GITHUB_ENV
else
git commit -m 'feat(${{ github.event.inputs.appName }}): Update to version ${{ github.event.inputs.version }}'
echo "title=feat(${{ github.event.inputs.appName }}): Update to version ${{ github.event.inputs.version }}" >> $GITHUB_ENV
fi
echo "::set-output name=commit::true"
# Open PR using this new branch
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.OPENSOURCE_BOT_TOKEN}}
committer: ${{ env.GIT_COMMITTER_NAME }} <${{ env.GIT_COMMITTER_EMAIL }}>
author: ${{ env.GIT_AUTHOR_NAME }} <${{ env.GIT_AUTHOR_EMAIL }}>
branch: ${{ github.event.inputs.appName }}/${{ github.event.inputs.version }}
base: master
title: ${{ env.title }}
body: |
Automated PR created via New Relic One Catalog Manager.
Initiated by: @${{ github.event.inputs.user }}
labels: |
Automated PR
- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"