<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: pierresaid</title>
    <description>The latest articles on DEV Community by pierresaid (@pierresaid).</description>
    <link>https://dev.to/pierresaid</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F190172%2Fd3ae83b6-f11e-46a0-a63d-5a2c8b7d2cd9.png</url>
      <title>DEV Community: pierresaid</title>
      <link>https://dev.to/pierresaid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pierresaid"/>
    <language>en</language>
    <item>
      <title>Deploy your projects to Github Pages with GitHub Actions</title>
      <dc:creator>pierresaid</dc:creator>
      <pubDate>Sat, 31 Aug 2019 21:02:06 +0000</pubDate>
      <link>https://dev.to/pierresaid/deploy-node-projects-to-github-pages-with-github-actions-4jco</link>
      <guid>https://dev.to/pierresaid/deploy-node-projects-to-github-pages-with-github-actions-4jco</guid>
      <description>&lt;p&gt;In this post I am going to explain how to set up a basic workflow that uses an existing GitHub action. This workflow will deploy a static web site to GitHub Pages every time a change is made to the master branch.&lt;/p&gt;

&lt;p&gt;For this we are going to use the &lt;a href="https://github.com/marketplace/actions/deploy-to-github-pages"&gt;Deploy to GitHub Pages Action&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Create our workflow
&lt;/h1&gt;

&lt;p&gt;The workflows of the repository are stored in the &lt;code&gt;.github/workflows/&lt;/code&gt; folder. &lt;/p&gt;

&lt;p&gt;Create in this folder a .yml file (e.g. &lt;code&gt;deploy-to-gh-pages.yml&lt;/code&gt; you can name it however you want) and paste this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;
&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build and Deploy&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;# defaults to master&lt;/span&gt;
&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;build-and-deploy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Checkout 🛎️&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v3&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install and Build 🔧&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;npm install&lt;/span&gt;
          &lt;span class="s"&gt;npm run-script build&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy 🚀&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;JamesIves/github-pages-deploy-action@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;folder&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;build&lt;/span&gt; &lt;span class="c1"&gt;# The folder the action should deploy.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The build step
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install and Build 🔧&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
        &lt;span class="s"&gt;npm install&lt;/span&gt;
        &lt;span class="s"&gt;npm run-script build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this section we put the script required to compile the code before deploying. If there is no need just remove this section.&lt;/p&gt;

&lt;h3&gt;
  
  
  Options
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;branch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gh-pages&lt;/span&gt;
        &lt;span class="na"&gt;folder&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dist&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All those options are environment variables that will be used by the &lt;a href="https://github.com/marketplace/actions/deploy-to-github-pages"&gt;Deploy to GitHub Pages Action&lt;/a&gt; in order to work.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;BRANCH&lt;/code&gt; option is the branch you wish to deploy the build files to. It is &lt;code&gt;gh-pages&lt;/code&gt; by default so that github automatically set up your github pages website.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You need to create the &lt;code&gt;gh-pages&lt;/code&gt; branch prior to this. The Action will fail if the branch does not exist.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;code&gt;folder&lt;/code&gt; option is the folder in your repository that you want to deploy. It usually is &lt;code&gt;dist&lt;/code&gt; for Vue.js apps or &lt;code&gt;build&lt;/code&gt; for React.js apps.&lt;/p&gt;

&lt;p&gt;the &lt;code&gt;permissions&lt;/code&gt; filed is required so that the script has sufficient rights to run.&lt;/p&gt;

&lt;p&gt;Optionally if you want to use a specific access token you can add the &lt;code&gt;token&lt;/code&gt; option like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;token: ${{ secrets.ACCESS_TOKEN }}&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This option is the access token used to authorize the action to manipulate your repository.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can generate this token in &lt;a href="https://github.com/settings/tokens"&gt;Profile Settings / Developer settings&lt;/a&gt; and add it in your repository's &lt;code&gt;secrets&lt;/code&gt; in &lt;code&gt;Settings/Secrets&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Custom domain name
&lt;/h1&gt;

&lt;p&gt;If you are using a custom domain name you will need to add beforehand a &lt;code&gt;CNAME&lt;/code&gt; file at the root of the &lt;code&gt;gh_pages&lt;/code&gt; branch with your domain name in it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;e.g. &lt;code&gt;dev.to&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you are &lt;strong&gt;not&lt;/strong&gt; using a custom domain name, then do not forget to specify that your project is not hosted at the server root.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Vue.js apps add this in &lt;code&gt;vue.config.js&lt;/code&gt;. &lt;a href="https://cli.vuejs.org/config/#publicpath"&gt;Further information&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;publicPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/repository-name/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For React.js apps add this your &lt;code&gt;package.json&lt;/code&gt;. &lt;a href="https://create-react-app.dev/docs/deployment#building-for-relative-paths"&gt;Further information&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"homepage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"https://yourusername.github.io/repository-name"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Specify the branch (Optional)
&lt;/h1&gt;

&lt;p&gt;By default, this will use the &lt;code&gt;master&lt;/code&gt; branch when changes are made. &lt;/p&gt;

&lt;p&gt;To change that replace the &lt;code&gt;on: [push]&lt;/code&gt; for this property with name of the branch of which you'd like this to run on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;note: Your workflows won't appear in the &lt;code&gt;Actions&lt;/code&gt; tab if they are not pushed on the &lt;code&gt;master&lt;/code&gt; branch. However, you can still access your workflow’s runs in the commit's detail.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;That's it! Push your changes and you can now watch the magic operate in the Actions tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v49viQLZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1djjhixx18vkdh8n9sl5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v49viQLZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1djjhixx18vkdh8n9sl5.png" alt="Alt Text" width="880" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we can see that the app was deployed to GitHub Pages &lt;em&gt;You can check out your deployments by clicking the &lt;code&gt;environment&lt;/code&gt; button in the Code tab&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aaP_-Ce7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ys92cfjv10gdk7onx63f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aaP_-Ce7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ys92cfjv10gdk7onx63f.png" alt="Alt Text" width="880" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might have to disable/enable the github page option in the settings tab the first time the action run. You can do that by changing the &lt;em&gt;Source&lt;/em&gt; setting to &lt;code&gt;master&lt;/code&gt; then back to &lt;code&gt;gh-pages&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The link to your live app is &lt;code&gt;https://yourusername.github.io/repository-name&lt;/code&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>webdev</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
