|
| 1 | +name: "Deploy Quarto Site" |
| 2 | +description: "Deploys a Quarto static site to a VPS" |
| 3 | +author: "Your Name <[email protected]>" |
| 4 | + |
| 5 | +inputs: |
| 6 | + vps-ip: |
| 7 | + description: "The IP address of the VPS that is set up as a webserver" |
| 8 | + required: true |
| 9 | + site-name: |
| 10 | + description: "The name of the site to deploy (usually a single word)" |
| 11 | + required: true |
| 12 | + ssh-private-key: |
| 13 | + description: "The private SSH key that grants access to the VPS" |
| 14 | + required: true |
| 15 | + uses-python: |
| 16 | + description: "Whether the site uses Python for generating content" |
| 17 | + required: false |
| 18 | + default: "false" |
| 19 | + uses-r: |
| 20 | + description: "Whether the site uses R for generating content" |
| 21 | + required: false |
| 22 | + default: "false" |
| 23 | + ssh-user: |
| 24 | + description: 'The user to connect to the VPS as (defaults to "webadmin")' |
| 25 | + required: false |
| 26 | + default: "webadmin" |
| 27 | + |
| 28 | +runs: |
| 29 | + using: "composite" |
| 30 | + steps: |
| 31 | + - name: Check variables set |
| 32 | + # Make it easier to see when environment setup is incorrect |
| 33 | + run: | |
| 34 | + if [ -z "${{ inputs.ssh-private-key }}" ]; then |
| 35 | + echo "ssh-private-key is not set" |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + if [ -z "${{ inputs.vps-ip }}" ]; then |
| 39 | + echo "vps-ip is not set" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + if [ -z "${{ inputs.site-name }}" ]; then |
| 43 | + echo "site-name is not set" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Checkout code |
| 48 | + uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + ref: ${{ github.ref }} |
| 51 | + |
| 52 | + - name: Setup static site builder (e.g. Quarto) |
| 53 | + uses: quarto-dev/quarto-actions/setup@v2 |
| 54 | + |
| 55 | + ### Install Python dependencies (to run any python for generating quarto content) |
| 56 | + # Note: assumes using `uv` for dependency management |
| 57 | + - name: Install uv |
| 58 | + if: ${{ inputs.uses-python }} |
| 59 | + uses: astral-sh/setup-uv@v5 |
| 60 | + with: |
| 61 | + enable-cache: true |
| 62 | + version: "0.6.x" |
| 63 | + |
| 64 | + - name: Setup Python |
| 65 | + uses: actions/setup-python@v5 # Use official because GH caches it |
| 66 | + with: |
| 67 | + python-version-file: "pyproject.toml" |
| 68 | + |
| 69 | + - name: Install dependencies and activate virtual environment |
| 70 | + run: uv sync |
| 71 | + |
| 72 | + ### Install R dependencies (to run any R for generating quarto content) |
| 73 | + # Note: This is untested (I don't use R, so don't know if this is correct) |
| 74 | + - name: Setup R |
| 75 | + if: ${{ inputs.uses-r }} |
| 76 | + uses: r-lib/actions/setup-r@v1 |
| 77 | + with: |
| 78 | + r-version: "4.1" |
| 79 | + ############ |
| 80 | + |
| 81 | + - name: Build static site files |
| 82 | + uses: quarto-dev/quarto-actions/render@v2 |
| 83 | + |
| 84 | + - name: Send static files to server |
| 85 | + |
| 86 | + with: |
| 87 | + host: ${{ inputs.vps-ip }} |
| 88 | + username: ${{ inputs.ssh-user }} |
| 89 | + key: ${{ secrets.ssh-private-key }} |
| 90 | + port: 22 |
| 91 | + source: ./_site/ # This is the default build directory for Quarto |
| 92 | + target: sites/${{ inputs.site-name }}/static/ |
| 93 | + strip_components: 2 |
| 94 | + overwrite: true |
| 95 | + |
| 96 | + - name: Update frontend files on server |
| 97 | + |
| 98 | + with: |
| 99 | + host: ${{ inputs.vps-ip }} |
| 100 | + username: ${{ inputs.ssh-user }} |
| 101 | + key: ${{ secrets.ssh-private-key }} |
| 102 | + # Note: This script is present on the server from the webserver setup |
| 103 | + script: | |
| 104 | + ./scripts/webserver-update-static-files.sh |
0 commit comments