|
| 1 | +--- |
| 2 | +title: 'Deploying your website automatically' |
| 3 | +shortTitle: 'Deploy automatically' |
| 4 | +intro: 'Automate your code deployment with {% data variables.product.prodname_actions %} and {% data variables.product.prodname_pages %} to publish updates to a live site with every push to the main branch.' |
| 5 | +category: |
| 6 | + - Learn to code |
| 7 | +contentType: get-started |
| 8 | +versions: |
| 9 | + fpt: '*' |
| 10 | + ghes: '*' |
| 11 | + ghec: '*' |
| 12 | +--- |
| 13 | + |
| 14 | +Your feature is merged, so now you can share it. In this tutorial, you'll set up automatic deployment so every push to `main` publishes your software project to a live website. |
| 15 | + |
| 16 | +> [!NOTE] |
| 17 | +> The URL of your {% data variables.product.prodname_pages %} site depends on which version of {% data variables.product.github %} you use. |
| 18 | +> * On {% data variables.product.prodname_dotcom_the_website %}, your site is published at `YOUR-USERNAME.github.io/REPOSITORY`. |
| 19 | +> * If you use {% data variables.product.github %} with data residency on {% data variables.enterprise.data_residency_site %}, your site is published at `pages.SUBDOMAIN.ghe.com/YOUR-USERNAME/REPOSITORY`, where `SUBDOMAIN` is your enterprise's subdomain. |
| 20 | +> * On {% data variables.product.prodname_ghe_server %}, your site is published at `pages.HOSTNAME/YOUR-USERNAME/REPOSITORY`, where `HOSTNAME` is the hostname of your {% data variables.product.prodname_ghe_server %} instance. |
| 21 | +
|
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +* A `stargazers-log` repository with your merged feature. If you haven't merged it yet, see [AUTOTITLE](/get-started/start-your-journey/reviewing-your-proposed-changes). |
| 25 | + |
| 26 | +## Enabling {% data variables.product.prodname_pages %} |
| 27 | + |
| 28 | +Set up {% data variables.product.prodname_pages %} to host your site, and use {% data variables.product.prodname_actions %} to build and publish it. |
| 29 | + |
| 30 | +1. On {% data variables.product.github %}, navigate to your `stargazers-log` repository. |
| 31 | +1. Under your repository name, click **Settings**. |
| 32 | +1. In the sidebar, in the "Code and automation" section, click **Pages**. |
| 33 | +1. Under "Build and deployment", from the **Source** dropdown, select **{% data variables.product.prodname_actions %}**. |
| 34 | + |
| 35 | +Leave the other settings at their defaults. Next, you'll create **your own workflow** to build and deploy your site automatically. |
| 36 | + |
| 37 | +## Creating a deployment workflow |
| 38 | + |
| 39 | +A workflow is a set of automated steps that {% data variables.product.prodname_actions %} runs for you. Add one that builds and deploys your site whenever you push to `main`. |
| 40 | + |
| 41 | +1. In your repository, create a file named `.github/workflows/deploy.yml`. |
| 42 | + 1. On the main page of your `stargazers-log` repository above the list of files, click **{% octicon "plus" aria-hidden="true" aria-label="plus" %}**, then click **{% octicon "plus" aria-hidden="true" aria-label="plus" %} Create new file**. |
| 43 | + 1. In the file name field, type `.github/workflows/deploy.yml`. |
| 44 | +1. Add the following workflow content. |
| 45 | + |
| 46 | + ```yaml copy |
| 47 | + name: Deploy to GitHub Pages |
| 48 | + |
| 49 | + on: |
| 50 | + push: |
| 51 | + branches: |
| 52 | + - main |
| 53 | + |
| 54 | + permissions: |
| 55 | + contents: read |
| 56 | + pages: write |
| 57 | + id-token: write |
| 58 | + |
| 59 | + jobs: |
| 60 | + deploy: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + environment: |
| 63 | + name: github-pages |
| 64 | + url: {% raw %}${{ steps.deployment.outputs.page_url }}{% endraw %} |
| 65 | + steps: |
| 66 | + - name: Checkout |
| 67 | + uses: {% data reusables.actions.action-checkout %} |
| 68 | + - name: Setup Pages |
| 69 | + uses: actions/configure-pages@v5 |
| 70 | + - name: Upload artifact |
| 71 | + {%- ifversion fpt or ghec %} |
| 72 | + uses: actions/upload-pages-artifact@v4 |
| 73 | + {%- elsif ghes %} |
| 74 | + uses: actions/upload-pages-artifact@v2 |
| 75 | + {%- endif %} |
| 76 | + with: |
| 77 | + path: '.' |
| 78 | + - name: Deploy to GitHub Pages |
| 79 | + {%- ifversion fpt or ghec %} |
| 80 | + id: deployment |
| 81 | + uses: actions/deploy-pages@v4 |
| 82 | + {%- elsif ghes %} |
| 83 | + id: deployment |
| 84 | + uses: actions/deploy-pages@v2 |
| 85 | + {%- endif %} |
| 86 | + ``` |
| 87 | + |
| 88 | +1. Commit the file directly to the `main` branch. |
| 89 | + |
| 90 | +## Understanding the workflow |
| 91 | + |
| 92 | +Each part of the workflow has a job to do: |
| 93 | + |
| 94 | +* **`on`** tells {% data variables.product.prodname_actions %} to run the workflow on every push to `main`. |
| 95 | +* **`permissions`** grant the workflow the access it needs to publish to {% data variables.product.prodname_pages %}. |
| 96 | +* **`environment`** connects the job to your {% data variables.product.prodname_pages %} site and exposes the published URL as {% raw %}`${{ steps.deployment.outputs.page_url }}`{% endraw %}. |
| 97 | +* **`steps`** check out your code, prepare {% data variables.product.prodname_pages %}, upload your files as an artifact, and deploy them to your live site. |
| 98 | + |
| 99 | +## Viewing your live site |
| 100 | + |
| 101 | +After you commit the workflow, {% data variables.product.prodname_actions %} runs it automatically. |
| 102 | + |
| 103 | +1. In your repository, click the **Actions** tab to watch the workflow run. |
| 104 | +1. Click the latest workflow run to see a summary of the job details. |
| 105 | +1. When the run completes, open your published site at {% ifversion fpt or ghec %}`https://YOUR-USERNAME.github.io/stargazers-log/`{% elsif ghes %}`https://pages.HOSTNAME/YOUR-USERNAME/stargazers-log/`{% endif %}. Replace `YOUR-USERNAME` with your username{% ifversion ghes %}, and replace `HOSTNAME` with your {% data variables.product.prodname_ghe_server %} hostname{% endif %}. |
| 106 | + * For example, if your {% data variables.product.github %} account username is `octocat`, your site is at {% ifversion fpt or ghec %}`https://octocat.github.io/stargazers-log/`{% elsif ghes %}`https://pages.HOSTNAME/octocat/stargazers-log/`{% endif %}. |
| 107 | + |
| 108 | +From now on, every push to `main` redeploys your site with your latest changes. |
| 109 | + |
| 110 | +## What you built |
| 111 | + |
| 112 | +Across this series, you built a complete software project and practiced the {% data variables.product.github %} workflow: |
| 113 | + |
| 114 | +| Stage | What you learned | |
| 115 | +| ----- | ---------------- | |
| 116 | +| Creating your software project | Repositories, README files | |
| 117 | +| Planning your work | Issues, Projects (project boards) | |
| 118 | +| Connecting locally | {% data variables.product.prodname_desktop %}, cloning | |
| 119 | +| Writing and storing code | Branches, commits, pull requests, {% data variables.product.prodname_copilot_short %} | |
| 120 | +| Reviewing changes | Pull request reviews, {% data variables.product.prodname_copilot_short %} | |
| 121 | +| Deploying automatically | {% data variables.product.prodname_actions %}, {% data variables.product.prodname_pages %} | |
| 122 | + |
| 123 | +## Next steps |
| 124 | + |
| 125 | +* Expand your understanding of Git and {% data variables.product.github %}. For more information, see [AUTOTITLE](/get-started/start-your-journey/git-and-github-learning-resources). |
| 126 | +* Explore {% data variables.copilot.copilot_chat_short %} to learn faster and get help as you code. For more information, see [AUTOTITLE]({% ifversion ghes %}/enterprise-cloud@latest/{% endif %}/copilot/concepts/chat){% ifversion ghes %} in the {% data variables.product.prodname_ghe_cloud %} documentation{% endif %}. |
| 127 | +* Go deeper with AI and learn how agents can act like a practical coding partner by turning ideas into small actionable steps, generating examples, and handling repetitive work. For more information, see [AUTOTITLE]({% ifversion ghes %}/enterprise-cloud@latest/{% endif %}/copilot/concepts/agents){% ifversion ghes %} in the {% data variables.product.prodname_ghe_cloud %} documentation{% endif %}. |
| 128 | +* Learn more about automating your software projects with {% data variables.product.prodname_actions %} workflows. For more information, see [AUTOTITLE](/actions/get-started/understand-github-actions). |
| 129 | +* Add a custom domain or explore more ways to publish your website with {% data variables.product.prodname_pages %}. For more information, see [AUTOTITLE](/pages/getting-started-with-github-pages). |
0 commit comments