Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Deploy a WordPress Theme with GitHub Actions
Matteo Barbero
Matteo Barbero

Posted on

Deploy a WordPress Theme with GitHub Actions

Is it possible to deploy a WordPress theme directly from GitHub?

Minified code, “bundler” of various types, package manager for JavaScript and PHP and so forth… These are just some of the reasons for choosing toautomate the deployment of a WordPress Theme.

Sure it’s always possible to upload files with ftp every time, but why do it manually when GitHub can take care of everything?

Welcome to the guide to automate the deployment

First, the theme code must be in a GitHub repository.

Create a .github folder inside the repo. Inside this folder create another folder called workflows and inside it a main.yml file. You can give this file any name you like, the important thing is to keep the .yml extension.

The folder structure will look like this:.github / workflows / main.yml

The .yml file

Let’s start creating our workflow to automate the deployment

name: Deploy via FTPon:  push:    branches: [ main ]
Enter fullscreen modeExit fullscreen mode

name will simply be the name that we will display in the Actions tab of the repository

Image description
on: things get interesting here. We define our trigger here. In this case we want to deploy to the push, but we have added a filter: we are only interested in the push done to the main branch. In this way we can have a development branch, perhaps automating the deployment of this on a staging site as well.

jobs:  build:    runs-on: ubuntu-latest    defaults:      run:        shell: bash
Enter fullscreen modeExit fullscreen mode

Now we come to the actions, jobs, which will follow, by default in parallel, our workflow. build will be the name of our only job

runs-on: where do we want to run our workflow? GitHub gives us several possibilities listed here.

The last three lines are used to set a default shell for all runs

 steps:    - uses: actions/checkout@v2      with:        fetch-depth: 2    - name: FTP Deploy WP Theme      uses: SamKirkland/FTP-Deploy-Action@4.3.2      with:        server: FTP SERVER        username: FTP USERNAME        password: ${{ secrets.FTP_PASSWORD }}        server-dir: FTP DIR        exclude: |          **/.git*          **/.git*/**          **/node_modules/**
Enter fullscreen modeExit fullscreen mode

We are at the final steps of our workflow. We just have to worry about writing our ftp server address and username, as well as the destination folder (our theme folder).

Since this file will be accessible from the repository, we can keep some settings like our password secret. To do this we can set a new secret key from theSetting / Secrets / Actions tab

Image description

Secret key GitHub repository
Are you tired of reading and just want to make a nice copy and paste? Find the .yml file and ready-made folder structurehere

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Dedicated Backend developer, merging passion with precision. Navigating between Italy and The Netherlands, crafting robust digital solutions.
  • Location
    Italy | Netherlands
  • Work
    Software Engineer | PHP Developer | Backend Developer
  • Joined

More fromMatteo Barbero

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp