Skip to content

Add example of using environment variables with GitHub Pages deployment #11767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/content/docs/en/guides/deploy/github.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,28 @@ export default defineConfig({
The official Astro [action](https://github.com/withastro/action) scans for a lockfile to detect your preferred package manager (`npm`, `yarn`, `pnpm`, or `bun`). You should commit your package manager's automatically generated `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, or `bun.lockb` file to your repository.
:::

2. On GitHub, go to your repository’s **Settings** tab and find the **Pages** section of the settings.
2. (Optional) If you pass environment variables to your Astro project during local development or when previewing builds, you will need to define any public variables in the `deploy.yml` file in order for them to be processed when you deploy to GitHub Pages. (See the [GitHub documentation on setting secrets](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#creating-configuration-variables-for-a-repository) for adding private environment variables.)

3. Choose **GitHub Actions** as the **Source** of your site.
```yaml title="deploy.yml"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout your repository using git
uses: actions/checkout@v4
- name: Install, build, and upload your site
uses: withastro/action@v3
env:
# Use single quotation marks for the variable value
PUBLIC_EVM_WALLET_ADDRESS: '0x4bFc229A40d41698154336aFF864f61083E76659'
```


3. On GitHub, go to your repository’s **Settings** tab and find the **Pages** section of the settings.

4. Choose **GitHub Actions** as the **Source** of your site.

4. Commit the new workflow file and push it to GitHub.
5. Commit the new workflow file and push it to GitHub.
</Steps>

Your site should now be published! When you push changes to your Astro project’s repository, the GitHub Action will automatically deploy them for you.
Expand Down