diff --git a/.github/workflows/quarto.yml b/.github/workflows/quarto.yml index e495c42..3e290f9 100644 --- a/.github/workflows/quarto.yml +++ b/.github/workflows/quarto.yml @@ -1,29 +1,12 @@ -name: quarto website +name: quarto-website # Controls when the workflow will run on: # Triggers the workflow on push or pull request events but only for the specified branches push: - branches: [ "main", "dev" ] - # pull_request: - # branches: [ "main", "dev" ] - - # # Allows you to run this workflow manually from the Actions tab - # workflow_dispatch: - -# Debugging log info -# https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging - -# temporarily use conditional statement to skip PR while troubleshooting -# env: A map of variables that are available to the steps of all jobs in the workflow. - # The env context contains variables that have been set in a workflow, job, or step. -# env: -# RUN_PR_STEP: "${{ false }}" - -# The vars context contains custom configuration variables set at the organization, repository, and environment levels. -# repository or environment variables can be set on Github or the GH Actions extension in VSCode -# https://github.com/jennylsmith/jennylsmith.github.io/settings/variables/actions -# if statements can only access thse expression contexts: github, inputs, vars, needs + branches: [ "main", "dev", "main_pr_test", "dev_pr_test"] + # Allows you to run this workflow manually from the Actions tab or gh CLI + workflow_dispatch: # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. @@ -33,7 +16,7 @@ concurrency: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: - contents: read + contents: write pages: write id-token: write pull-requests: write @@ -46,65 +29,125 @@ jobs: runs-on: ubuntu-latest env: QUARTO_VERSION: 1.5.57 + OUTPUT_DIR: docs + CACHE_PATH: '**/docs/*.*' + # Steps represent a sequence of tasks that will be executed as part of the job steps: - # install quarto - - name: install quarto CLI - run: | - wget -O ${{ runner.temp }}/quarto.deb https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-amd64.deb \ - && sudo dpkg -i ${{ runner.temp }}/quarto.deb # checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: checkout uses: actions/checkout@v4 - + # setup gh pages - name: setup pages id: pages uses: actions/configure-pages@v5 + - name: restore artifacts + id: cache-artifacts + uses: actions/cache/restore@v4 + with: + path: ${{ env.OUTPUT_DIR }} + key: ${{ github.ref_name }}-${{ github.sha }}-key + + # install quarto + - name: install quarto CLI + if: steps.cache-artifacts.outputs.cache-hit != 'true' + run: | + wget -O ${{ runner.temp }}/quarto.deb --quiet https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-amd64.deb \ + && sudo dpkg -i ${{ runner.temp }}/quarto.deb + # render the website - name: render website + if: steps.cache-artifacts.outputs.cache-hit != 'true' run: quarto render # upload the rendered website (artifact) - name: upload artifact + id: artifact uses: actions/upload-pages-artifact@v3 with: - path: ./docs + path: ${{ env.OUTPUT_DIR }} + + # cache rendered website artifacts + - name: Cache Artifacts + id: create-cache + uses: actions/cache/save@v4 + with: + path: ${{ env.OUTPUT_DIR }} + key: ${{ github.ref_name }}-${{ github.sha }}-key # pull request + # https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs pull_request: - if: ${{ vars.RUN_PR_STEP == true }} + if: ${{ github.ref_name == 'dev_pr_test' }} needs: build runs-on: ubuntu-latest + environment: + name: dev + env: + BASE: main_pr_test steps: - name: checkout uses: actions/checkout@v4 - - name: create pull request - id: cpr - uses: peter-evans/create-pull-request@v7 with: - commit-message: "merge dev into main" - branch: dev - base: pr_actions_test - assignees: jennylsmith - reviewers: jennylsmith - + token: ${{ secrets.GH_PAT }} + ref: main_pr_test + - name: gh-cli-pr + run: | + echo ${{ secrets.GH_PAT }} | gh auth login --with-token && \ + gh pr create -B $BASE -H ${{ github.ref_name }} --title "PR for ${{ github.sha }} on RUN_ID ${{ github.run_id }}" --body "PR for ${{ github.sha }}" --draft && \ + gh auth logout + # - name: gh-cli-pr + # run: + + # - name: create-pull-request + # id: cpr + # uses: peter-evans/create-pull-request@v7 + # with: + # commit-message: merge dev into main + # title: PR from ${{ github.run_id }} + # draft: always-true + # branch: ${{ github.ref }} + # deploy job deploy: + if: ${{ github.ref_name == 'main' }} # Add a dependency to the job needs: build - # add and if statement later? ${{ github.event.repository.default_branch }} # Deploy to the github-pages environment + # Settings and variables here: https://github.com/jennylsmith/jennylsmith.github.io/settings/environments + # environment: + # name: github-pages + # url: ${{ steps.deployment.outputs.page_url }} environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - + name: dev # Specify runner runs-on: ubuntu-latest # deploy to gh pages steps: - - name: deploy to GitHub pages - id: deployment - uses: actions/deploy-pages@v4 + - name: "vars example" + run: | + echo "the gh branch that triggered the workflow is $GITHUB_REF_NAME" + echo "debug set to $ACTIONS_RUNNER_DEBUG" + # - name: deploy to GitHub pages + # id: deployment + # uses: actions/deploy-pages@v4 + + +#### NOTES + +# Debugging log info +# https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging + +# temporarily use conditional statement to skip PR while troubleshooting +# env: A map of variables that are available to the steps of all jobs in the workflow. + # The env context contains variables that have been set in a workflow, job, or step. +# env: +# RUN_PR_STEP: "${{ false }}" + +# The vars context contains custom configuration variables set at the organization, repository, and environment levels. +# repository or environment variables can be set on Github or the GH Actions extension in VSCode +# https://github.com/jennylsmith/jennylsmith.github.io/settings/variables/actions +# if statements can only access thse expression contexts: github, inputs, vars, needs diff --git a/README.md b/README.md index 8f23ef5..db20441 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ using the following command in a terminal: quarto preview --render all --no-watch-inputs --no-browse ``` -For new features or fixes, create an issue on github in a new branch. +For new features or fixes, create an issue on github and create a new branch with the changes. Then open a pull request using `gh` commandline utility to merge changes into the `dev` branch, like the example below for issue #4.