Skip to content

Commit

Permalink
ci: create deployment manually
Browse files Browse the repository at this point in the history
A few months ago, as a result of security recommendations from Github,
we adjusted PR Previews to be deployed via Workflow run.

This had the unintentional side-effect of making these deployments appear
as if they came from the "develop" branch, as `workflow_run` triggers
always run in the "develop" context.

I've done two things:

1. Adjusted the deployment job to now manually create deployments
   as opposed to using the Github native `environment` because environment
   does not support skipping automatic deployment creation:
   https://github.com/orgs/community/discussions/36919

2. Set the sha for the deployment from the calling workflow_run.

This makes the Github UI work as expected.
  • Loading branch information
damienwebdev committed Feb 1, 2024
1 parent 18565d2 commit 09248db
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/deploy_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
deploy_daffio:
name: Deploy Daff.io
runs-on: ubuntu-latest
environment:
name: preview
url: ${{ steps.vercel.outputs.url }}
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
steps:
- uses: graycoreio/github-actions/angular-universal-vercel-wflw-run@main
Expand All @@ -38,3 +35,25 @@ jobs:
vercel-org: ${{ secrets.VERCEL_ORG }}
vercel-project-id: ${{ secrets.VERCEL_DAFFIO_NEXT_PROJECT_ID }}
ng-version: '17'
- name: Create Deployment
uses: actions/github-script@v7
with:
script: |
const { data } = await github.rest.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "${{ github.event.workflow_run.head_branch }}",
auto_merge: false,
required_contexts: [],
environment: 'preview'
});
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: data.id,
state: 'success',
log_url: "${{ github.event.workflow_run.workflow_url }}",
environment_url: "${{ steps.vercel.outputs.url }}",
description: 'Deployment succeeded!',
});

0 comments on commit 09248db

Please sign in to comment.