withastro / action

A GitHub Action that deploys your Astro project to GitHub Pages
Other
143 stars 31 forks source link

Automate checkout, deploy, and `--site` + `--base` config #29

Open natemoo-re opened 9 months ago

natemoo-re commented 9 months ago

After looking at how we recommend this action is used, it turns out we can do a bit more to make it simple for people to use. This would be a great v2 for this action.

Based on https://github.com/actions/configure-pages, we can automatically infer the correct --site and --base flags for Astro to use when building. This eliminates the main gotcha with our current setup (that you almost certainly need to update your config with these values).

This also automatically uses actions/checkout@v4 to pull your repo and actions/deploy-pages@v2 to deploy your site to GitHub Pages. These changes mean that our recommended setup is greatly simplified.

name: Deploy to GitHub Pages

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deploy.outputs.url }}
    steps:
      - name: Build and Deploy
        id: deploy
        uses: withastro/action@configure-site
        # when this is released, it will be withastro/action@v2

Instead of running npm run build, we now run the astro CLI directly. Honestly this is the change I'm most hesitant about, because some folks might want CI to fail if astro-check fails or use pre/post-build scripts. This change would skip those and just do astro build. Open to feedback!

KorigamiK commented 9 months ago

If this is working maybe you look into merging?

natemoo-re commented 9 months ago

@KorigamiK If you want to try this PR while we're working on it, you're welcome to point your repository to it! Using withastro/action@configure-site should do the trick.

ollecoffee commented 6 months ago

Looking forward to test this @natemoo-re ๐Ÿ’ฏ what did I miss here? https://github.com/ollegkz/olle.coffee/actions/runs/7401803673/job/20138353320

natemoo-re commented 6 months ago

Looking forward to test this @natemoo-re ๐Ÿ’ฏ what did I miss here? https://github.com/ollegkz/olle.coffee/actions/runs/7401803673/job/20138353320

That is probably on my end! I'm guessing the command is not correct so Bun is printing its help message instead

ollecoffee commented 6 months ago

Seems to work as of https://github.com/withastro/action/commit/6e05a33aadf24152da04c9a037e5a23a53fb2852 as you can see https://github.com/ollegkz/olle.coffee/actions/runs/7423744689/job/20201840905 but the url is no longer printed out in the deploy complete step ๐Ÿ˜ฎ

Compare https://github.com/ollegkz/olle.coffee/actions/runs/7423744689/job/20201840905 complete job with https://github.com/ollegkz/olle.coffee/actions/runs/7400679346/job/20134828466 :suprised_pikachu:

natemoo-re commented 6 months ago

Thanks @ollegkz! I forked your repo so I can test changes directly against it. I think it's bun-specific.

ollecoffee commented 5 months ago

Any luck on merging this @natemoo-re? ๐Ÿฅ‡

swift502 commented 5 months ago

Works for root deployment. And base works too. ๐Ÿ™

To summarize then, the "site" param in astro.config.js is no longer mandatory for deployment? But base still has a few gotchas, if deploying with a base:

But I hope we can simplify the docs a bit once this is merged.

ollecoffee commented 5 months ago

Hmm, I just noticed that actions/configure-pages@v3 uses node16 and actions/configure-pages@v4 uses node20 :)

natemoo-re commented 1 month ago

I'm converting this to a draft since I haven't had time to finish this up! I still think this is a better solution that what we have currently, but I'm hesitant about spawning the astro CLI directly.

If anyone else wants to pick this up, please do. Otherwise I will try to circle back to this in the future.