Skip to content
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

Github Actions separate to two jobs and staging #624

Merged
merged 11 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
98 changes: 0 additions & 98 deletions .github/actions/help-command/action.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ concurrency:
cancel-in-progress: true

env:
APP_NAME: ${{ vars.REVIEW_APP_PREFIX }}-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
APP_NAME: ${{ vars.REVIEW_APP_PREFIX }}-pr-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
CPLN_ORG: ${{ vars.CPLN_ORG_STAGING }}
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
Expand All @@ -33,10 +33,10 @@ jobs:
debug:
uses: ./.github/workflows/debug-workflow.yml
with:
debug_enabled: false # Will still run if vars.DEBUG_WORKFLOW is true
Process-Deployment-Command:
needs: debug # Add this to ensure debug runs first
debug_enabled: false

process-deployment:
needs: debug
if: |
(github.event_name == 'pull_request') ||
(github.event_name == 'push') ||
Expand All @@ -45,12 +45,13 @@ jobs:
github.event.issue.pull_request &&
contains(github.event.comment.body, '/deploy-review-app'))
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
issues: write

outputs:
pr_number: ${{ env.PR_NUMBER }}
pr_sha: ${{ env.PR_SHA }}
pr_ref: ${{ steps.getRef.outputs.PR_REF }}
do_deploy: ${{ env.DO_DEPLOY }}
comment_id: ${{ steps.create-comment.outputs.comment-id }}
deployment_id: ${{ steps.init-deployment.outputs.result }}
steps:
# Initial checkout only for pull_request and push events
- name: Checkout code
Expand Down Expand Up @@ -157,13 +158,6 @@ jobs:
echo "PR_REF=$(echo $PR_DATA | jq -r .headRefName)" >> $GITHUB_OUTPUT
echo "PR_SHA=$(echo $PR_DATA | jq -r .headRefOid)" >> $GITHUB_ENV

- name: Checkout PR code
if: github.event_name == 'workflow_dispatch' || github.event_name == 'issue_comment'
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ steps.getRef.outputs.PR_SHA }}

- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
Expand Down Expand Up @@ -253,26 +247,6 @@ jobs:
});
core.setOutput('comment-id', result.data.id);

- name: Update Comment - Building
if: env.DO_DEPLOY != 'false'
uses: actions/github-script@v7
with:
script: |
const buildingMessage = [
`🏗️ Building Docker image for PR #${process.env.PR_NUMBER}, commit ${process.env.PR_SHA}`,
'',
`📝 [View Build Logs](${process.env.WORKFLOW_URL})`,
'',
process.env.CONSOLE_LINK
].join('\n');

await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.create-comment.outputs.comment-id }},
body: buildingMessage
});

- name: Set Deployment URLs
id: set-urls
if: env.DO_DEPLOY != 'false'
Expand Down Expand Up @@ -305,30 +279,6 @@ jobs:
'https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/-info)'
);

- name: Update Status - Building
if: env.DO_DEPLOY != 'false'
uses: actions/github-script@v7
with:
script: |
const buildingMessage = [
'🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + '${{ env.PR_SHA }}',
'',
'📝 [View Build Logs](' + process.env.WORKFLOW_URL + ')',
'',
process.env.CONSOLE_LINK
].join('\n');

await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.create-comment.outputs.comment-id }},
body: buildingMessage
});

- name: Checkout PR Branch
if: env.DO_DEPLOY != 'false'
run: git checkout ${{ steps.getRef.outputs.PR_REF }}

- name: Initialize GitHub Deployment
if: env.DO_DEPLOY != 'false'
uses: actions/github-script@v7
Expand Down Expand Up @@ -359,17 +309,70 @@ jobs:

return deployment.data.id;

build:
needs: process-deployment
if: needs.process-deployment.outputs.do_deploy != 'false'
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.build.outputs.image_tag }}
comment_id: ${{ needs.process-deployment.outputs.comment_id }}
Comment on lines +295 to +297
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix missing output value assignment.

The job declares image_tag as an output but the value is never set in the build step. This could cause deployment failures.

Ensure the build step sets the output:

       - name: Build Docker Image
         id: build
         uses: ./.github/actions/build-docker-image
         with:
           app_name: ${{ env.APP_NAME }}
           org: ${{ vars.CPLN_ORG_STAGING }}
           commit: ${{ needs.process-deployment.outputs.pr_sha }}
           PR_NUMBER: ${{ needs.process-deployment.outputs.pr_number }}
+        # Add this step to set the output
+      - name: Set image tag output
+        if: success()
+        run: echo "image_tag=${{ env.APP_NAME }}:${{ needs.process-deployment.outputs.pr_sha }}" >> $GITHUB_OUTPUT
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
outputs:
image_tag: ${{ steps.build.outputs.image_tag }}
comment_id: ${{ needs.process-deployment.outputs.comment_id }}
outputs:
image_tag: ${{ steps.build.outputs.image_tag }}
comment_id: ${{ needs.process-deployment.outputs.comment_id }}
🧰 Tools
🪛 actionlint (1.7.4)

317-317: property "image_tag" is not defined in object type {}

(expression)

pr_number: ${{ needs.process-deployment.outputs.pr_number }}
do_deploy: ${{ needs.process-deployment.outputs.do_deploy }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.process-deployment.outputs.pr_ref }}

- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
token: ${{ secrets.CPLN_TOKEN_STAGING }}
org: ${{ vars.CPLN_ORG_STAGING }}

- name: Update Status - Building
uses: actions/github-script@v7
with:
script: |
const buildingMessage = [
'🏗️ Building Docker image for PR #${{ needs.process-deployment.outputs.pr_number }}, commit ${{ needs.process-deployment.outputs.pr_sha }}',
'',
'📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
'',
process.env.CONSOLE_LINK
].join('\n');

await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ needs.process-deployment.outputs.comment_id }},
body: buildingMessage
});

- name: Build Docker Image
if: env.DO_DEPLOY != 'false'
id: build
uses: ./.github/actions/build-docker-image
with:
app_name: ${{ env.APP_NAME }}
org: ${{ vars.CPLN_ORG_STAGING }}
commit: ${{ env.PR_SHA }}
PR_NUMBER: ${{ env.PR_NUMBER }}
commit: ${{ needs.process-deployment.outputs.pr_sha }}
PR_NUMBER: ${{ needs.process-deployment.outputs.pr_number }}

deploy:
needs: build
if: needs.build.outputs.do_deploy != 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
token: ${{ secrets.CPLN_TOKEN_STAGING }}
org: ${{ vars.CPLN_ORG_STAGING }}

- name: Update Status - Deploying
if: env.DO_DEPLOY != 'false'
uses: actions/github-script@v7
with:
script: |
Expand All @@ -378,7 +381,7 @@ jobs:
'',
'⏳ Waiting for deployment to be ready...',
'',
'📝 [View Deploy Logs](' + process.env.WORKFLOW_URL + ')',
'📝 [View Deploy Logs](${{ env.WORKFLOW_URL }})',
'',
process.env.CONSOLE_LINK
].join('\n');
Expand Down
Loading
Loading