Skip to content

Commit

Permalink
adds GitHub deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderniebuhr committed Mar 19, 2024
1 parent 4d9f56a commit a6ae216
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ on:
jobs:
site:
runs-on: ubuntu-latest
permissions:
actions: read
checks: read
contents: read
deployments: write
issues: write
discussions: read
packages: read
pages: read
pull-requests: write
repository-projects: read
security-events: read
statuses: read
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
Expand All @@ -25,11 +38,52 @@ jobs:
- uses: moonrepo/run-report-action@a92e881fd7c6bd680f64bfa1219ac7ddf3c3d009 # v1.6.1
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: deployment
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const githubBranch = process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME;
const productionEnvironment = githubBranch === 'main';
const environmentName = `[site] (${productionEnvironment ? "Production" : githubBranch})`;
const deployment = github.rest.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref: githubBranch || context.ref,
auto_merge: false,
description: "Site Cloudflare Pages",
required_contexts: [],
environment: environmentName,
production_environment: productionEnvironment,
});
core.setOutput("deployment-id", deployment.data.id)
- uses: cloudflare/wrangler-action@7c01cc48d88a1f83b4716e0557c168854a9dcdb8 # v3.4.1
id: wrangler
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
wranglerVersion: "3.34.2"
workingDirectory: "apps/site"
packageManager: pnpm
command: pages deploy dist --project-name astrolicious
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
DEPLOYMENT_ID: ${{ steps.deployment.outputs.deployment-id }}
DEPLOYMENT_URL: ${{ steps.wrangler.outputs.deployment-url }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const githubBranch = process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME;
const productionEnvironment = githubBranch === 'main';
const environmentName = `[site] (${productionEnvironment ? "Production" : ${githubBranch}})`;
const deployment = github.rest.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: process.env.DEPLOYMENT_ID,
environment: environmentName,
environment_url: process.env.DEPLOYMENT_URL,
production_environment: productionEnvironment,
description: "Cloudflare Pages",
state: "success",
auto_inactive: false,
});

0 comments on commit a6ae216

Please sign in to comment.