Skip to content

Commit b5fed3b

Browse files
danny-burrowsjasikparkFredKSchott
authoredJul 23, 2021
πŸ“˜ DOC: Adding github actions example to deploy.md (withastro#823)
* Adding github actions example to deploy.md * Update wording and example Made the suggested changes * Apply suggestions from code review Co-authored-by: Caleb Jasik <[email protected]> Co-authored-by: Fred K. Schott <[email protected]> Co-authored-by: Caleb Jasik <[email protected]> Co-authored-by: Fred K. Schott <[email protected]>
1 parent 599ad13 commit b5fed3b

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed
 

β€Ždocs/src/pages/guides/deploy.md

+59-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,65 @@ By default, the build output will be placed at `dist/`. You may deploy this `dis
6868
6969
### GitHub Actions
7070

71-
TODO: We'd love an example action snippet to share here!
71+
1. Set the correct `buildOptions.site` in `astro.config.mjs`
72+
2. Create the file `.github/workflows/main.yml` and add in the yaml below. Make sure to edit in your own details.
73+
3. In Github go to Settings > Developer settings > Personal Access tokens. Generate a new token with repo permissions.
74+
4. In the astro project repo (not \<YOUR USERNAME\>.github.io) go to Settings > Secrets and add your new personal access token with the name `API_TOKEN_GITHUB`.
75+
5. When you push changes to the astro project repo CI will deploy them to \<YOUR USERNAME\>.github.io for you.
76+
77+
```yaml
78+
# Workflow to build and deploy to your Github Pages repo.
79+
80+
# Edit your project details here.
81+
# Remember to add API_TOKEN_GITHUB in repo Settings > Secrets as well!
82+
env:
83+
githubEmail: <YOUR GITHUB EMAIL ADDRESS>
84+
deployToRepo: <NAME OF REPO TO DEPLOY TO (E.G. <YOUR USERNAME>.github.io)>
85+
86+
name: Github Pages Astro CI
87+
88+
on:
89+
# Triggers the workflow on push and pull request events but only for the main branch
90+
push:
91+
branches: [ main ]
92+
pull_request:
93+
branches: [ main ]
94+
95+
# Allows you to run this workflow manually from the Actions tab.
96+
workflow_dispatch:
97+
98+
jobs:
99+
100+
deploy:
101+
runs-on: ubuntu-latest
102+
103+
steps:
104+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
105+
- uses: actions/checkout@v2
106+
107+
# Install dependencies with npm
108+
- name: Install dependencies
109+
run: npm ci
110+
111+
# Build the project and add .nojekyll file to supress default behaviour
112+
- name: Build
113+
run: |
114+
npm run build
115+
touch ./dist/.nojekyll
116+
117+
# Push to your pages repo
118+
- name: Push to pages repo
119+
uses: cpina/github-action-push-to-another-repository@main
120+
env:
121+
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
122+
with:
123+
source-directory: 'dist'
124+
destination-github-username: ${{ github.actor }}
125+
destination-repository-name: ${{ env.deployToRepo }}
126+
user-email: ${{ env.githubEmail }}
127+
commit-message: Deploy ORIGIN_COMMIT
128+
target-branch: main
129+
```
72130
73131
### Travis CI
74132

0 commit comments

Comments
 (0)