Skip to content

Testing that Review App Deployment Workflow only redeploys on Pull Request Trigger #645

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

Merged
merged 9 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 12 additions & 48 deletions .github/workflows/deploy-to-control-plane-review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,68 +113,24 @@ jobs:
# Check if app exists and save state
if ! cpflow exists -a ${{ env.APP_NAME }}; then
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
exit 0
echo "Canceling job as review app has not been previously deployed."
fi
echo "APP_EXISTS=false" >> $GITHUB_ENV
else
echo "APP_EXISTS=true" >> $GITHUB_ENV
fi

- name: Validate Deployment Request
id: validate
run: |
# Skip validation if deployment is already disabled
if [[ "${{ env.DO_DEPLOY }}" == "false" ]]; then
echo "Skipping validation - deployment already disabled"
exit 0
fi

if ! [[ "${{ github.event_name }}" == "workflow_dispatch" || \
"${{ github.event_name }}" == "issue_comment" || \
"${{ github.event_name }}" == "pull_request" || \
"${{ github.event_name }}" == "push" ]]; then
echo "Error: Unsupported event type ${{ github.event_name }}"
exit 1
fi

# Set DO_DEPLOY based on event type and conditions
if [[ "${{ github.event_name }}" == "pull_request" && \
("${{ github.event.action }}" == "opened" || \
"${{ github.event.action }}" == "synchronize" || \
"${{ github.event.action }}" == "reopened") ]]; then
echo "DO_DEPLOY=true" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "push" ]]; then
echo "DO_DEPLOY=true" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "DO_DEPLOY=true" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then
if [[ "${{ github.event.issue.pull_request }}" ]]; then
# Trim spaces and check for exact command
COMMENT_BODY=$(echo "${{ github.event.comment.body }}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [[ "$COMMENT_BODY" == "/deploy-review-app" ]]; then
echo "DO_DEPLOY=true" >> $GITHUB_ENV
else
echo "DO_DEPLOY=false" >> $GITHUB_ENV
echo "Skipping deployment - comment '$COMMENT_BODY' does not match '/deploy-review-app'"
fi
else
echo "DO_DEPLOY=false" >> $GITHUB_ENV
echo "Skipping deployment for non-PR comment"
fi
fi
if [[ "${{ env.DO_DEPLOY }}" == "false" ]]; then
exit 0
fi

- name: Setup Control Plane App if Not Existing
if: env.APP_EXISTS == 'false'
if: env.APP_EXISTS == 'false' && github.event_name != 'pull_request'
env:
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
run: |
echo "🔧 Setting up new Control Plane app..."
cpflow setup-app -a ${{ env.APP_NAME }} --org ${{ vars.CPLN_ORG_STAGING }}
echo "APP_EXISTS=true" >> $GITHUB_ENV

- name: Create Initial Comment
if: env.APP_EXISTS == 'true'
uses: actions/github-script@v7
id: create-comment
with:
Expand All @@ -188,6 +144,7 @@ jobs:
core.setOutput('comment-id', result.data.id);

- name: Set Deployment URLs
if: env.APP_EXISTS == 'true'
id: set-urls
uses: actions/github-script@v7
with:
Expand Down Expand Up @@ -219,6 +176,7 @@ jobs:
);

- name: Initialize GitHub Deployment
if: env.APP_EXISTS == 'true'
uses: actions/github-script@v7
id: init-deployment
with:
Expand Down Expand Up @@ -248,6 +206,7 @@ jobs:
return deployment.data.id;

- name: Update Status - Building
if: env.APP_EXISTS == 'true'
uses: actions/github-script@v7
with:
script: |
Expand All @@ -267,6 +226,7 @@ jobs:
});

- name: Build Docker Image
if: env.APP_EXISTS == 'true'
id: build
uses: ./.github/actions/build-docker-image
with:
Expand All @@ -276,6 +236,7 @@ jobs:
PR_NUMBER: ${{ env.PR_NUMBER }}

- name: Update Status - Deploying
if: env.APP_EXISTS == 'true'
uses: actions/github-script@v7
with:
script: |
Expand All @@ -297,13 +258,16 @@ jobs:
});

- name: Deploy to Control Plane
if: env.APP_EXISTS == 'true'
run: cpflow deploy-image -a ${{ env.APP_NAME }} --run-release-phase --org ${{ vars.CPLN_ORG_STAGING }} --verbose

- name: Retrieve App URL
if: env.APP_EXISTS == 'true'
id: workload
run: echo "WORKLOAD_URL=$(cpln workload get rails --gvc ${{ env.APP_NAME }} | tee | grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' | head -n1)" >> "$GITHUB_OUTPUT"

- name: Update Status - Deployment Complete
if: env.APP_EXISTS == 'true'
uses: actions/github-script@v7
with:
script: |
Expand Down
2 changes: 1 addition & 1 deletion client/app/bundles/comments/components/Footer/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Footer extends BaseComponent {
</a>
<a href="https://x.com/railsonmaui" className="flex gap-4 items-center">
<div className="w-16 h-16 bg-[url('../images/twitter_64.png')]" />
Rails On Maui on X
Rails On Maui on Twitter
</a>
</div>
</footer>
Expand Down