Skip to content

Commit

Permalink
Set environment variables for workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
atteggiani committed Nov 7, 2023
1 parent 28f1653 commit e8f1fb4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/create_pr_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true

env:
PR: ${{ github.event.number }}
TARGET_FOLDER: pr_preview/pr-${{ github.event.number }}
TARGET_BRANCH: gh-pages

jobs:
build-and-deploy-preview:
runs-on: ubuntu-latest
Expand All @@ -32,10 +37,10 @@ jobs:
- name: Add preview on gh-pages branch
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
branch: ${{ env.TARGET_BRANCH }}
folder: pr_preview
target-folder: pr_preview/pr-${{ github.event.number }}
commit-message: Deploy preview for PR ${{ github.event.number }} 🛫
target-folder: ${{ env.TARGET_FOLDER }}
commit-message: Deploy preview for PR ${{ env.PR }} 🛫
force: false

# - name: Deploy to Github pages
Expand All @@ -48,16 +53,16 @@ jobs:
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
number: ${{ github.event.number }}
number: ${{ env.PR }}
message: "\
PR Preview
:---:
🛫 Deployed preview to
https://access-hive.org.au/pr_preview/pr-${{ github.event.number }}
https://access-hive.org.au/pr_preview/pr-${{ env.PR }}
on branch [gh-pages]\
(${{ github.server_url }}/${{ github.repository }}/tree/gh-pages) \
on branch [${{ env.TARGET_BRANCH }}]\
(${{ github.server_url }}/${{ github.repository }}/tree/${{ env.TARGET_BRANCH }}) \
- ${{ env.DATE }}
"
18 changes: 11 additions & 7 deletions .github/workflows/remove_pr_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,39 @@ concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true

env:
PR: ${{ github.event.number }}
TARGET_FOLDER: pr_preview/pr-${{ github.event.number }}
TARGET_BRANCH: gh-pages

jobs:
close-preview:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: gh-pages
ref: ${{ env.TARGET_BRANCH }}

- name: Remove pr-preview
shell: bash
run: |
folder=pr-preview/pr-${{ github.event.number }}
if [ ! -d $folder ]
if [ ! -d ${{ env.TARGET_FOLDER }} ]
then
echo "Nothing to remove!"
exit 0
fi
rm -rf $folder
echo "Deleted $folder folder."
rm -rf ${{ env.TARGET_FOLDER }}
echo "Removed pr preview for pr-${{ env.PR }}."
- name: Commit to gh-pages
shell: bash
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add .
git commit -m "Deleted 'pr-preview/pr-${{ github.event.number }}' folder."
git push origin gh-pages
git commit -m "Deleted '${{ env.TARGET_FOLDER }}' folder."
git push origin ${{ env.TARGET_BRANCH }}
# - name: Deploy to Github-pages

Expand Down

0 comments on commit e8f1fb4

Please sign in to comment.