Skip to content

Publish pull request content on netlify #4

Publish pull request content on netlify

Publish pull request content on netlify #4

#
# Copyright (C) 2022 Red Hat, Inc.
#
# Licensed 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.
#
# SPDX-License-Identifier: Apache-2.0
# NOTE: Because this worklow is using secrets, it cannot run directly on a pull-request workflow, which is running in the context of the forked repository.
name: Publish pull request content on netlify
on:
workflow_run:
workflows:
- 'Build website on pull request'
types:
- completed
jobs:
publish:
name: Publish content of the website pull request on netlify
runs-on: ubuntu-22.04
steps:
- name: Download website content artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: website-content
path: content
- name: Set PR_NUMBER and PR_SHA variables
id: vars
run: |
echo "PR_NUMBER=$(<content/PR_NUMBER)" >> $GITHUB_OUTPUT
echo "PR_SHA=$(<content/PR_SHA)" >> $GITHUB_OUTPUT
- name: Publish preview netlify
uses: netlify/actions/cli@master
id: netlify-publish
with:
args: deploy --dir=content/website/build --functions=functions
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
- name: 'Update status of Pull Request'
uses: actions/github-script@v7
with:
script: |
const { repo: { owner, repo } } = context;
const netlifyUrl = '${{ steps.netlify-publish.outputs.NETLIFY_URL }}';
const sha = '${{ steps.vars.outputs.PR_SHA }}';
await github.rest.repos.createCommitStatus({ owner, repo, sha, state: "success", target_url: netlifyUrl, description: "See pull request website online", context: "netlify"})