-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to deployments #615
Merged
Merged
Changes from 4 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
ee08d3a
Pass correct arg
justin808 c790151
Set args with =
justin808 8355030
Address deprecation messages
justin808 f19d79f
Updates to deployment
justin808 e487791
updates
justin808 25e9502
Fixed the deployment_id output in the
justin808 de55983
fixes
justin808 5240c9b
fixes
justin808 2a1b9a3
fixes
justin808 8918cd2
fixes
justin808 fe262cb
fixes
justin808 80d841b
fixes
justin808 084f0d0
fixes
justin808 cac41c4
Fixed failure to deploy to review app
justin808 745ca0e
fixes
justin808 f77a610
fixes
justin808 87662fa
Updates, fix crash
justin808 4970fbe
fixes
justin808 e26cc72
fixes
justin808 29ade6f
Fixes
justin808 8db0511
fixes
justin808 b7a7229
fixes
justin808 1cff976
fixes
justin808 6cbdb04
fixes
justin808 0b15816
fixes
justin808 ae8a473
fixes
justin808 e6d5025
fixes
justin808 444ec85
fixes
justin808 8041a01
fixes
justin808 b03b6d7
fixes
justin808 a12e0d4
fixes
justin808 98649f2
fixes
justin808 b2e710a
fixes
justin808 c54a544
fixes
justin808 c80ff43
fixes
justin808 40473cc
fixes
justin808 038cf8f
fixes
justin808 c25211f
fixes
justin808 304e642
fixes
justin808 4744c76
fixes
justin808 5c8b3ab
fixes
justin808 2a51c92
fixes
justin808 61213b9
fixes
justin808 e431bdf
fixes
justin808 895986c
fixes
justin808 3fe506e
fixes
justin808 585c02d
fixes
justin808 c46f595
fixes
justin808 65c64d1
fixes
justin808 e96ac82
doc changes
justin808 2be9c2f
Changes made:
justin808 5f50639
fixes
justin808 e0cf883
fixes
justin808 b27783e
added promotion and other fixes
justin808 66a4114
fixes
justin808 3426aca
fix-for-delete
justin808 92ad3a7
fix-for-delete
justin808 7d75738
fix-for-delete
justin808 d5b8b7f
fix-for-delete
justin808 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,103 @@ | ||
# Control Plane GitHub Action | ||
|
||
name: Deploy Review App to Control Plane | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Uncomment these lines to trigger the workflow on pull request events | ||
# pull_request: | ||
# branches: | ||
# - master | ||
|
||
# deploy on comment "/deploy-review-app" | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
branches: [master] | ||
issue_comment: | ||
types: [created, edited] | ||
types: [created] | ||
|
||
concurrency: | ||
group: review-app-${{ github.event.pull_request.number || github.event.issue.number }} | ||
cancel-in-progress: true | ||
|
||
# Convert the GitHub secret variables to environment variables for use by the Control Plane CLI | ||
env: | ||
CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}} | ||
CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}} | ||
# Uncomment this line to use the PR number from the pull requests trigger event (that trigger is commented) | ||
# PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} | ||
PR_NUMBER: ${{ github.event.issue.number }} | ||
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} | ||
|
||
jobs: | ||
deploy-to-control-plane-review: | ||
if: ${{ github.event_name != 'issue_comment' || (github.event.comment.body == '/deploy-review-app' && github.event.issue.pull_request) }} | ||
if: | | ||
github.event_name == 'workflow_dispatch' || | ||
github.event_name == 'pull_request' || | ||
(github.event_name == 'issue_comment' && | ||
github.event.comment.body == '/deploy-review-app' && | ||
github.event.issue.pull_request) | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
app_url: ${{ steps.deploy.outputs.app_url }} | ||
deployment_id: ${{ steps.create-deployment.outputs.deployment_id }} | ||
|
||
steps: | ||
- name: Create GitHub Deployment | ||
id: create-deployment | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const deployment = await github.rest.repos.createDeployment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
ref: context.sha, | ||
environment: 'review-app', | ||
auto_merge: false, | ||
required_contexts: [] | ||
}); | ||
return deployment.data.id; | ||
|
||
- name: Get PR HEAD Ref | ||
if: ${{ github.event_name == 'issue_comment' }} | ||
id: getRef | ||
run: echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT | ||
run: | | ||
echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Checkout source code from Github | ||
- name: Checkout source code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ steps.getRef.outputs.PR_REF || github.ref }} | ||
|
||
- name: Add GitHub Comment | ||
if: ${{ github.event_name == 'issue_comment' }} | ||
- name: Update deployment status (in_progress) | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
await github.rest.repos.createDeploymentStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: "We started working on your review-app deployment. You can track progress in the `Actions` Tab [here](https://github.com/shakacode/react-webpack-rails-tutorial/actions/workflows/deploy-to-control-plane-review.yml) on Github." | ||
}) | ||
deployment_id: ${{ steps.create-deployment.outputs.deployment_id }}, | ||
state: 'in_progress', | ||
description: 'Deployment is in progress' | ||
}); | ||
|
||
- name: Get PR number | ||
if: ${{ github.event_name != 'issue_comment' }} | ||
run: | | ||
echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\"" | ||
if [ -z "$PR_NUMBER" ]; then | ||
echo "PR_NUMBER is not in the trigger event. Fetching PR number from open PRs." | ||
REF="${{ github.ref }}" | ||
REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix | ||
echo "REF: \"$REF\"" | ||
API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls?state=open" \ | ||
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') | ||
PR_NUMBER=$(echo "$API_RESPONSE" | jq '.[] | select(.head.ref=="'$REF'") | .number') | ||
fi | ||
echo "PR_NUMBER: $PR_NUMBER" | ||
if [ -z "$PR_NUMBER" ]; then | ||
echo "PR_NUMBER is not set. Aborting." | ||
exit 1 | ||
fi | ||
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | ||
- name: Get App Name | ||
run: | | ||
echo "PR_NUMBER: ${{ env.PR_NUMBER }}" | ||
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> "$GITHUB_ENV" | ||
echo "App Name: ${{ env.APP_NAME }}" | ||
- uses: ./.github/actions/deploy-to-control-plane | ||
# ... rest of your existing steps ... | ||
|
||
- name: Update deployment status (success) | ||
if: success() | ||
uses: actions/github-script@v7 | ||
with: | ||
app_name: ${{ env.APP_NAME }} | ||
org: ${{ env.CPLN_ORG }} | ||
script: | | ||
await github.rest.repos.createDeploymentStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
deployment_id: ${{ steps.create-deployment.outputs.deployment_id }}, | ||
state: 'success', | ||
environment_url: '${{ steps.deploy.outputs.app_url }}', | ||
description: 'Deployment successful' | ||
}); | ||
|
||
- name: Update deployment status (failure) | ||
if: failure() | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
await github.rest.repos.createDeploymentStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
deployment_id: ${{ steps.create-deployment.outputs.deployment_id }}, | ||
state: 'failure', | ||
description: 'Deployment failed' | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix shell script quoting.
Add double quotes around variables to prevent word splitting and globbing:
📝 Committable suggestion
🧰 Tools
🪛 actionlint (1.7.4)
53-53: shellcheck reported issue in this script: SC2086:info:1:27: Double quote to prevent globbing and word splitting
(shellcheck)
53-53: shellcheck reported issue in this script: SC2086:info:1:117: Double quote to prevent globbing and word splitting
(shellcheck)