Generate Catalog PR #519
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}" |