Preview deploy #195
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# Copyright (c) 2021 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 | |
# | |
# SPDX-License-Identifier: Apache-2.0 | |
# | |
name: Preview deploy | |
on: | |
workflow_run: | |
workflows: | |
- Preview build | |
types: | |
- completed | |
jobs: | |
success: | |
name: Preview deploy | |
runs-on: ubuntu-latest | |
if: github.event.workflow_run.event == 'pull_request' | |
steps: | |
- name: Download preview-build artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
name: preview-build | |
- name: Set variables | |
id: vars | |
run: | | |
echo "::set-output name=pr_number::$(<PR_NUMBER)" | |
echo "::set-output name=pr_sha::$(<PR_SHA)" | |
echo "::set-output name=deploy_domain::$(echo ${{ github.repository }}-$(<PR_NUMBER).surge.sh | sed s#/#-#)" | |
echo "::set-output name=project::$(find build/ -mindepth 1 -maxdepth 1 -type d)" | |
- name: Deploy | |
id: deploy | |
env: | |
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} | |
run: | | |
npx surge --project ${{ steps.vars.outputs.project }} --domain ${{ steps.vars.outputs.deploy_domain }} --token ${{ secrets.SURGE_TOKEN }} | |
- name: Update status Comment | |
uses: actions-cool/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
🎊 Navigate the preview: https://${{ steps.vars.outputs.deploy_domain }} 🎊 | |
<!-- Sticky Pull Request Comment --> | |
body-include: "<!-- Sticky Pull Request Comment -->" | |
number: ${{ steps.vars.outputs.pr_number }} | |
- name: Job failure | |
if: ${{ failure() }} | |
uses: actions-cool/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
Deploy PR Preview failed. | |
<!-- Sticky Pull Request Comment --> | |
body-include: "<!-- Sticky Pull Request Comment -->" | |
number: ${{ steps.vars.outputs.pr_number }} |