From a01d407932612bcf7e15c28fd1df30678c95a7cb Mon Sep 17 00:00:00 2001 From: John Murphy <107207111+jmurphy-res@users.noreply.github.com> Date: Wed, 3 Jan 2024 13:56:13 -0600 Subject: [PATCH] PWA-1219: Reusable Deployment Workflow (#76) * Add package * Add docs * Change input token * Update input namespace * Fix composition structure * Remove env * Fix indent * Fix composite * Fix composition * Composition * Add shell * Shell * Update token input * Input naming/docs * Remove actor --- README.md | 1 + package.json | 1 + web-create-release-pr/README.md | 24 ++++++++++ web-create-release-pr/action.yml | 77 ++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 web-create-release-pr/README.md create mode 100644 web-create-release-pr/action.yml diff --git a/README.md b/README.md index def8ef89..d351608a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ The following are our current actions. Go to its directories for a more detailed | [twistlock](/twistlock) | Run twistlock on repository | Active | | [publish-releases](/publish-releases) | Bump version and publish packages that have been modified. | Active | | [publish-previews](/publish-previews) | Publish preview package(s) from pull request. | Active | +| [web-create-release-pr](/web-create-release-pr) | Creates a release candidate branch and pull request (PR) | Active | | [auth0-add-origin](/auth0-add-origin) | Add a URL (such as a preview URL) to an Auth0 Client | Deprecated | | [auth0-remove-origin](/auth0-remove-origin) | Remove a URL (such as a preview URL) from an Auth0 Client | Deprecated | diff --git a/package.json b/package.json index 52317ca8..207d93f9 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "auth0-remove-origin", "twistlock", "start-and-check", + "web-create-release-pr", "core/*" ] }, diff --git a/web-create-release-pr/README.md b/web-create-release-pr/README.md new file mode 100644 index 00000000..959be9cf --- /dev/null +++ b/web-create-release-pr/README.md @@ -0,0 +1,24 @@ +# Web - Create Release PR + +Creates a release candidate branch and pull request (PR) + +## Usage + +```yaml +name: Prod - Create Release Candidate + +on: + workflow_dispatch: + +env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + +jobs: + create-release-pr: + uses: resideo/actions/web-create-release-pr@master + with: + fromBranch: stage + toBranch: master + rcBranchPrefix: release + prLabel: Prod Release +``` \ No newline at end of file diff --git a/web-create-release-pr/action.yml b/web-create-release-pr/action.yml new file mode 100644 index 00000000..4a836b7c --- /dev/null +++ b/web-create-release-pr/action.yml @@ -0,0 +1,77 @@ +name: Create Release Candidate + +inputs: + fromBranch: + description: 'Source branch name. Ex: develop' + required: true + type: string + toBranch: + description: 'Destination branch name. Ex: stage' + required: true + type: string + rcBranchPrefix: + description: 'RC branch prefix name. Ex: stage-release' + required: true + type: string + prLabel: + description: 'Pull request label. Ex: STAGE RELEASE' + required: true + type: string + githubToken: + description: 'GITHUB_TOKEN' + default: '${{ github.token }}' + +runs: + using: "composite" + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + with: + token: ${{ inputs.githubToken }} + + - uses: volta-cli/action@v1 + + - name: Set RC Branch Name + shell: bash + run: echo "rc_branch=$(date +${{ inputs.rcBranchPrefix }}/%Y.%m.%d.%H%M)" >> $GITHUB_ENV + + - name: Create RC Branch 🛠 + shell: bash + run: | + git fetch --all --unshallow + git checkout ${{ inputs.fromBranch }} + git pull + git checkout ${{ inputs.toBranch }} + git checkout -b ${{ env.rc_branch }} + git merge ${{ inputs.fromBranch }} + git push --set-upstream origin ${{ env.rc_branch }} + + - name: Generate Pull Request Body + shell: bash + run: | + echo "👑 An automated PR to merge *${{ inputs.fromBranch }}* to *${{ inputs.toBranch }}* 👑" > pr_msg + + - name: Get Pull Request Body + id: vars + shell: bash + run: echo ::set-output name=pr_body::$(cat pr_msg) + + - name: Create Pull Request 🛠 + uses: repo-sync/pull-request@v2 + with: + source_branch: ${{ env.rc_branch }} + destination_branch: ${{ inputs.toBranch }} + pr_title: '(Stage) ${{ env.rc_branch }} ' + pr_body: ${{ steps.vars.outputs.pr_body }} + pr_label: ${{ inputs.prLabel }} + + - name: Get Pull Request Number + id: pr-number + shell: bash + run: echo "pull_request_number=$(gh pr view --json number -q .number || echo "")" >> $GITHUB_OUTPUT + + - name: Comment on Pull Request + id: pr-comment + shell: bash + run: | + gh pr comment ${{ steps.pr-number.outputs.pull_request_number }} --body "Merge this PR manually by selecting '**Create a merge commit**' *not* 'Squash and merge'" \ No newline at end of file