Skip to content

Instantly share code, notes, and snippets.

@carlynorama
Last active November 4, 2022 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlynorama/a9f75dab91a2c25870bc7bc04e4fb36f to your computer and use it in GitHub Desktop.
Save carlynorama/a9f75dab91a2c25870bc7bc04e4fb36f to your computer and use it in GitHub Desktop.
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
paths:
- 'Output/**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
# Allow one concurrent deployment
# concurrency:
# group: "pages"
# cancel-in-progress: true
jobs:
copy_job:
name: Copy my folder
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
#token: ${{ secrets.pat }}
- name: Do copy
env:
SRC_FOLDER_PATH: 'Output'
TARGET_BRANCH: 'gh-pages'
run: |
files=$(find $SRC_FOLDER_PATH -type f) # get the file list
git config --global user.name 'GitHub Action'
git config --global user.email 'action@github.com'
git fetch # fetch branches
git checkout $TARGET_BRANCH # checkout to your branch
git checkout ${GITHUB_REF##*/} -- $files # copy files from the source branch
git add -A
git diff-index --quiet HEAD || git commit -am "deploy files" # commit to the repository (ignore if no modification)
git push origin $TARGET_BRANCH # push to remote branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment