DEV Community

Slava Vasenin for Visual Composer

Posted on

How to get WordPress plugin release in GitHub actions

We started to use GitHub actions to build Visual Composer release candidates in GitHub. This action will prepare a proper zip archive file which we can use to update our plugin in Wordpress.org.

We decided that the release will be built on the new tag. The tag will be the version of the published release.

on:
  push:
    tags:
      - '*'
Enter fullscreen mode Exit fullscreen mode

We already had the script which was able to create a valid zip archive of Visual Composer Website Builder for Wordpress.org. It looks like this.

$ node _infrastructure/vcwb-builder/builder plugin -b VERSION -p ./_infrastructure
Enter fullscreen mode Exit fullscreen mode

Yeah, this script will set plugin version also -b VERSION. The question is how to get the version from GitHub tag. There is access to $GITHUB_REF where we can get tags. I decide to create variable get_version which can be used in other steps of the job.

- name: Get the version
  id: get_version
  run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
Enter fullscreen mode Exit fullscreen mode

Then we just need to use steps.version_version in the next step.

- name: Build project
  run: |
    yarn install
    node _infrastructure/vcwb-builder/builder plugin -b ${{ steps.get_version.outputs.VERSION }} -p ./_infrastructure
Enter fullscreen mode Exit fullscreen mode

The next action is to create Github release itself.

- name: Create Release
  id: create_release
  uses: actions/create-release@v1.0.0
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    tag_name: ${{ github.ref }}
    release_name: ${{ github.ref }}
    draft: false
    prerelease: false
Enter fullscreen mode Exit fullscreen mode

After release creation needs to upload our zip archive. I use actions/upload-release-asset@v1.0.1 action for that.

- name: Upload Release Asset
  id: upload_release_asset
  uses: actions/upload-release-asset@v1.0.1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    upload_url: ${{ steps.create_release.outputs.upload_url }}
    asset_path: ./_infrastructure/visualcomposer.zip
    asset_name: visualcomposer.zip
    asset_content_type: application/zip
Enter fullscreen mode Exit fullscreen mode

That's it. The full version of the configuration file you can check here.

Good luck ✌️

Top comments (0)