{"id":2098,"date":"2022-02-28T20:20:05","date_gmt":"2022-02-28T13:20:05","guid":{"rendered":"https:\/\/wptips.dev\/?p=2098"},"modified":"2022-10-10T09:38:32","modified_gmt":"2022-10-10T02:38:32","slug":"wordpress-workflow","status":"publish","type":"post","link":"https:\/\/pixelstudio.id\/blog\/wordpress-workflow\/","title":{"rendered":"Our WordPress Workflow with Github Action"},"content":{"rendered":"\n<p>Github Action is an <strong>automation tool<\/strong> to deploy your code whenever a new commit is pushed to Github.<\/p>\n\n\n\n<p>This article will teach you how to automatically upload the changes <strong>using FTP<\/strong>. We opted to use FTP instead of SSH because it works in all hosting.<\/p>\n\n\n\n<p>Let&#8217;s take a look at how we do it:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Git Folder Structure<\/h2>\n\n\n\n<p>We basically<strong> committed the whole WordPress folder<\/strong> while ignoring everything except the theme and custom plugins.<\/p>\n\n\n\n<p>Resulting in a repository that looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\/\n\u251c\u2500\u2500 wp-content\/\n\u2502   \u251c\u2500\u2500 themes\/\n\u2502   \u2502   \u251c\u2500\u2500 my-theme\/\n\u2502   \u251c\u2500\u2500 plugins\/\n\u2502   \u2502   \u251c\u2500\u2500 custom-plugin-if-any\/\n\u251c\u2500\u2500 .github\n\u2502   \u251c\u2500\u2500 workflow\/\n\u2502   \u2502   \u251c\u2500\u2500 deploy.yml\n\u251c\u2500\u2500 composer.json\n\u2514\u2500\u2500 .gitignore<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2022\/02\/deploywp-git-structure.jpg\" alt=\"\" class=\"wp-image-2105\" width=\"276\" height=\"247\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">composer.json<\/h3>\n\n\n\n<p>All the plugins that are available in wordpress.org are managed with Composer. The custom ones are committed to the git.<\/p>\n\n\n\n<p>If you don&#8217;t know how to use Composer for WP plugins, read the guide below:<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"https:\/\/pixelstudio.id\/blog\/composer-to-manage-plugins\/\"><strong>How to Use Composer<\/strong><\/a><\/div>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\">.gitignore<\/h3>\n\n\n\n<p>This will ignore all except your custom theme and custom plugins.<\/p>\n\n\n\n<p>You need to specify <strong>included plugins<\/strong> and <strong>excluded themes<\/strong> like shown below:<\/p>\n\n\n\n<pre title=\".gitignore\" class=\"wp-block-code\"><code class=\" line-numbers\">vendor\/\nwp-admin\/\nwp-includes\/\nwp-content\/*\n\n!wp-content\/plugins\/\nwp-content\/plugins\/*\n!wp-content\/plugins\/custom-plugin-if-any\n\n!wp-content\/themes\/\nwp-content\/themes\/twentynineteen\nwp-content\/themes\/twentytwenty\nwp-content\/themes\/twentytwentyone\nwp-content\/themes\/twentytwentytwo\nwp-content\/themes\/storefront\n\n\/*.php\n\/.htaccess\n\/wp-cli.local.yml\n\/composer.lock\n\/index.php\n\nnginx.conf\n.DS_Store\nnode_modules\/\nlogs\n*.log\nnpm-debug.log*\nreadme.html\nlicense.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">deploy.yml<\/h3>\n\n\n\n<p>This file contains the Action commands. It resides in the folder <code>.github\/workflows\/<\/code>.<\/p>\n\n\n\n<p>We have prepared <strong>two variations<\/strong> depending on whether your hosting supports SFTP or not.<\/p>\n\n\n\n<p><strong>For SFTP:<\/strong> (only a few hosting support this)<\/p>\n\n\n\n<pre title=\"deploy.yml\" class=\"wp-block-code\"><code class=\"\">name: Deploy via SFTP\non:\n  push:\n    branches:\n      - main\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions\/checkout@v1\n    - name: Deploy app\n      uses: sebastianpopp\/git-ftp-action@fix-ssl-issue\n      with:\n        url: \"sftp:\/\/myhosting.com\"\n        user: ${{ secrets.FTP_USERNAME }}\n        password: ${{ secrets.FTP_PASSWORD }}\n        options: \"--auto-init --insecure --remote-root \/home\/path\/to\/your\/folder\"<\/code><\/pre>\n\n\n\n<p>If you&#8217;re using an old repo, the branch name might be &#8220;master&#8221; instead of &#8220;main&#8221;. So change that in the code above.<\/p>\n\n\n\n<p><strong>For FTP:<\/strong> (most hostings only support this)<\/p>\n\n\n\n<pre title=\"deploy.yml\" class=\"wp-block-code\"><code class=\"\">name: Deploy via FTP\non:\n  push:\n    branches:\n      - main\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions\/checkout@v1\n    - name: git-ftp push\n      uses: sebastianpopp\/git-ftp-action@releases\/v3\n      with:\n        url: \"ftp.myhosting.com\/public_html\/mysite\"\n        user: ${{ secrets.FTP_USERNAME }}\n        password: ${{ secrets.FTP_PASSWORD }}<\/code><\/pre>\n\n\n\n<p><strong>Getting the correct URL<\/strong> is a bit tricky.<\/p>\n\n\n\n<p>It starts with the FTP base address. For example <code>ftp.myhosting.com<\/code>. Followed by the path to the site folder.<\/p>\n\n\n\n<p>But the path starts from where you landed in Filezilla. So if you landed in <code>\/www<\/code> and the path is <code>\/www\/public_html\/mysite<\/code>, no need to include the <code>\/www<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setup the Secrets<\/h2>\n\n\n\n<p>This is to replace the FTP_USERNAME and FTP_PASSWORD in our command. Follow the guide below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"533\" src=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2022\/02\/deploywp-secrets.jpg\" alt=\"\" class=\"wp-image-2106\" srcset=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2022\/02\/deploywp-secrets.jpg 750w, https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2022\/02\/deploywp-secrets-480x341.jpg 480w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<ol><li>Go to your Github and click &#8220;Settings&#8221; tab.<\/li><li>Click &#8220;Secrets&#8221; in the left sidebar.<\/li><li>Click &#8220;New repository secret&#8221; and create two variables named FTP_USERNAME and FTP_PASSWORD. Fill the values accordingly.<\/li><li>Done!<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Test It Out<\/h2>\n\n\n\n<p>Make changes in your code and commit it. Then open the &#8220;Actions&#8221; tab in Github. You should see the deployment in progress:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"181\" src=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2022\/02\/deploywp-test.jpg\" alt=\"\" class=\"wp-image-2107\" srcset=\"https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2022\/02\/deploywp-test.jpg 750w, https:\/\/pixelstudio.id\/blog\/wp-content\/uploads\/2022\/02\/deploywp-test-480x116.jpg 480w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>The initial commit will <strong>take quite a while<\/strong> (5-10 mins) depending on the number of files. After that, it will be much faster since it only uploads the modified file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>We have been using this workflow since 2016 with great success. Back then we were using a similar service called Bitbucket Pipeline.<\/p>\n\n\n\n<p>In short, we are using different methods for deploying different parts of WordPress:<\/p>\n\n\n\n<ol><li>Deploying theme &#8211; uses <strong>Github Action<\/strong>.<\/li><li>Deploying plugins &#8211; uses <strong>Composer <\/strong>If hosting supports SSH, otherwise use FTP manually.<\/li><li>Deploying database and images &#8211; use <a href=\"https:\/\/pixelstudio.id\/blog\/wp-sync-db\/\"><strong>WP Sync DB<\/strong><\/a>.<\/li><\/ol>\n\n\n\n<p>Although it looks confusing to use different methods, we rarely need to do #2 and #3. So we only need to focus on how to make #1 as quick and seamless as possible.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>If you have any question, let us know in the comment below<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to use Github to automatically deploy your WordPress theme changes based on commit. <\/p>\n","protected":false},"author":1,"featured_media":2108,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-2098","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general"],"blocksy_meta":"","_links":{"self":[{"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/posts\/2098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/comments?post=2098"}],"version-history":[{"count":14,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/posts\/2098\/revisions"}],"predecessor-version":[{"id":2221,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/posts\/2098\/revisions\/2221"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/media\/2108"}],"wp:attachment":[{"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/media?parent=2098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/categories?post=2098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pixelstudio.id\/blog\/wp-json\/wp\/v2\/tags?post=2098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}