Skip to content

Publish preview

Publish preview #1674

Workflow file for this run

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Publish preview
on:
workflow_run:
workflows: ["Pull request checks"]
types:
- completed
jobs:
preview:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download pull request artifact
uses: actions/github-script@v7
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const websiteArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == 'website'
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: websiteArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/website.zip', Buffer.from(download.data));
- name: Unzip website artifact
run: unzip -q website.zip
- name: Preview on Netlify
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: |
PR_NUMBER=$(head -1 pull_request/number)
PR_NUMBER=${PR_NUMBER//[^0-9]/}
PR_URL="https://github.com/apache/camel-website/pull/${PR_NUMBER}"
DEPLOY_URL=$(yarn preview:netlify --alias="pr-${PR_NUMBER}" --message="Preview for ${PR_URL}" --json 2> /dev/null |jq -r .deploy_url)
echo "DEPLOY_URL=${DEPLOY_URL}" >> $GITHUB_ENV
echo "ISSUE_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
- uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: Number(process.env.ISSUE_NUMBER),
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 Preview is available at ${process.env.DEPLOY_URL}`
})