{"id":8446,"date":"2020-07-12T21:06:34","date_gmt":"2020-07-12T21:06:34","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=8446"},"modified":"2020-07-12T21:08:07","modified_gmt":"2020-07-12T21:08:07","slug":"github-actions-publishing-changes-to-a-branch","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/github-actions-publishing-changes-to-a-branch\/","title":{"rendered":"GitHub Actions &#8211; publishing changes to a branch"},"content":{"rendered":"<p>If you want to do something like GitHub pages does with Jekyll, i.e. takes master and generates the website and then publishes the resultant files to the gh-pages branch, then you&#8217;ll need to set-up personal access tokens and use them in your GitHub action, for example<\/p>\n<ul>\n<li>Go to <a href=\"https:\/\/github.com\/settings\/tokens\" rel=\"noopener noreferrer\" target=\"_blank\">Personal access tokens<\/a><\/li>\n<li>Click on the &#8220;Generate new token&#8221; button<\/li>\n<li>In the Note field, give it a descriptive name so you know the purpose of the token<\/li>\n<li>If you&#8217;re wanting to interact with the repo (as we want to for this example) then check the repo checkbox to enable all repo options<\/li>\n<li>Click the &#8220;Generate token&#8221; button<\/li>\n<li>Copy the generated token for use in the next section<\/li>\n<\/ul>\n<p>Once we have a token we&#8217;re going to use this in our repositories. So assuming you have a repo created, do the following to store the token<\/p>\n<ul>\n<li>Go to your repository and click the &#8220;Settings&#8221; tab<\/li>\n<li>Select the &#8220;Secrets<\" option<\/li>\n<li>Click on the &#8220;New secret&#8221; button<\/li>\n<li>Give the secret a name, for example PUBLISH_TOKEN<\/li>\n<li>Paste the token from the previous section in the &#8220;Value&#8221; textbox<\/li>\n<li>Finally click the &#8220;Add secret&#8221; button<\/li>\n<\/ul>\n<p>This now stores the token along with the name\/key, which can then be used in our GitHub action .yml files, for example here&#8217;s a snippet of a GitHub action to publish a website that&#8217;s stored in master to the gh-pages branch.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n- name: GitHub Pages Publish\r\n  if: ${{ github.ref == 'refs\/heads\/master' }} \r\n    uses: peaceiris\/actions-gh-pages@v3.6.1\r\n    with:\r\n      github_token: ${{ secrets.PUBLISH_TOKEN }}\r\n      publish_branch: gh-pages\r\n      publish_dir: .\/public\r\n<\/pre>\n<p>In this example action, we check for changes on master, then use <a href=\"https:\/\/github.com\/peaceiris\/actions-gh-pages\" rel=\"noopener noreferrer\" target=\"_blank\">GitHub Actions for GitHub Pages<\/a> to publish to the gh-pages branch from the .\/public folder on master. Notice we use the secrets.PUBLISH_TOKEN which means GitHub actions will supply the token from our secrets setting using the name we gave for the secret.<\/p>\n<p>Obviously this example doesn&#8217;t build\/generate or otherwise do anything with the code on master, it simply takes what&#8217;s pushed to master\/public and publishes that to the gh-pages branch. Ofcourse if we combine this action with previous build\/generate steps as part of a build pipleline.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to do something like GitHub pages does with Jekyll, i.e. takes master and generates the website and then publishes the resultant files to the gh-pages branch, then you&#8217;ll need to set-up personal access tokens and use them in your GitHub action, for example Go to Personal access tokens Click on the &#8220;Generate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[304],"tags":[],"class_list":["post-8446","post","type-post","status-publish","format-standard","hentry","category-github-actions"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=8446"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8446\/revisions"}],"predecessor-version":[{"id":8451,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8446\/revisions\/8451"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=8446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=8446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=8446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}