Question

Web app deployment strategy

Posted December 31, 2021 129 views
WordPressGitHub Actions

Background/Context

I’m running a WordPress site on a DO droplet whose static js and CSS are generated via gulp tasks. For those interested, I’ll leave the contents of my gulpfile below. My entire WordPress site is stored on Github and I’m using GitHub Webhooks to auto-deploy new commits that reach the repo to my DO server.

Problem

I use SASS to facilitate writing styles (for anyone unfamiliar, SASS compiles to pure CSS). This is done via the compile:sass task in my gulpfile. Today, I need to run gulp locally and commit the built CSS file (style.css) to my repo so that the changes end up on my server. This is a bad practice and one I’d like to change. In an ideal world, should my server be executing gulp every time it receives a message from GitHub’s webhook? Are there additional build processes that I should implement to make my setup more bulletproof?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

From what you describe, your only use for gulp is to compile the sass to css.

Therefore, if you drop to writing css, there won’t be any need to compile anything, which means gulp won’t be needed, right?

If that’s the case, then you’ll only need to copy over the changes to DO and that’ll be all, whenever you make changes.

You can run gulp commands via Github Actions if that is a must also, that way, you don’t need to run those commands on your machine everytime before you push to Github

  • Thanks for the response @seanmavley. My question may not have been as clear as it should have but I don’t want to “drop to writing CSS”. I want to keep writing SASS, but I don’t want to have to send the compiled CSS to the server along with the changes to the SASS files. I think what you’re describing with running gulp commands via GitHub actions is what I had in mind. Some follow-up questions:

    • Is this considered a best practice, or at least an acceptable one?
    • Would this mean adding a call to gulp in the post-receive GitHub script I have set up on my server which currently executes git commands to pull in changes from my repo? While I’m at it, should I also execute npm install from this script?

    Thanks for your help!

    • Is this considered a best practice, or at least an acceptable one?

      Best? I can’t say. But it’s a common practice to do it that way.

      Would this mean adding a call to gulp in the post-receive GitHub script I have set up on my server which currently executes git commands to pull in changes from my repo? While I’m at it, should I also execute npm install from this script?

      In short, you’ll need to prep the github actions build environment in a way similar to your local machine, so as you can run your gulp commands.