Skip to content

Instantly share code, notes, and snippets.

@koen12344
Created February 6, 2023 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koen12344/e597f1edacec38fb3f2473b8427798dd to your computer and use it in GitHub Desktop.
Save koen12344/e597f1edacec38fb3f2473b8427798dd to your computer and use it in GitHub Desktop.
Github action to package & publish WP plugin to Freemius
name: Build plugin
on:
push:
if: startsWith(github.ref, 'refs/tags/v')
branches:
- main
- beta
- pending
jobs:
create-release:
runs-on: ubuntu-latest
env:
FS_USER_ID: ${{ secrets.FS_USER_ID }}
FS_PLUGIN_ID: ${{ secrets.FS_PLUGIN_ID }}
FS_PUBLIC_KEY: ${{ secrets.FS_PUBLIC_KEY }}
FS_SECRET_KEY: ${{ secrets.FS_SECRET_KEY }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Write release version
run: |
VERSION=${GITHUB_REF_NAME#v}
echo Version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- name: Set up Strauss
run: |
curl -o strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/download/0.13.0/strauss.phar
chmod +x strauss.phar
mv strauss.phar /usr/local/bin/strauss
- name: Set up WP-CLI
run: |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
- name: Set up Node
uses: actions/setup-node@v3
- name: Generate POT file
run: wp i18n make-pot ./ languages/product-sync-for-gbp.pot
- name: Create build directory
run: rsync -av --exclude='.git' --exclude-from='.gitignore' . build-plugin
- name: NPM Install & Build
working-directory: ./build-plugin
run: |
npm install
npm run build
- name: Composer install
working-directory: ./build-plugin
run: |
mkdir vendor-prefixed
composer install --no-dev --classmap-authoritative --prefer-dist
composer dump-autoload -a --ignore-platform-reqs
- name: Download Freemius SDK
working-directory: ./build-plugin
run: wget https://github.com/Freemius/wordpress-sdk/archive/master.zip -O wordpress-sdk-master.zip && unzip wordpress-sdk-master.zip && rm wordpress-sdk-master.zip && mv wordpress-sdk-master freemius
- name: Delete distignored files
working-directory: ./build-plugin
run: grep -v "^#" .distignore | xargs rm -rf
- name: Zip plugin
uses: montudor/action-zip@v1
with:
args: zip -qq -r product-sync-for-gbp.zip build-plugin
- name: Download freemius PHP SDK
run: git clone https://github.com/Freemius/php-sdk.git "./bin/freemius-php-api"
- name: Upload plugin to Freemius
run: |
RELEASE_STATE="pending"
if [[ "${GITHUB_REF##*/}" == "beta" ]]; then
RELEASE_STATE="beta"
elif [[ "${GITHUB_REF##*/}" == "main" ]]; then
RELEASE_STATE="released"
fi
php bin/freemius-deploy.php $FS_USER_ID $FS_PUBLIC_KEY $FS_SECRET_KEY product-sync-for-gbp.zip $FS_PLUGIN_ID false $VERSION $RELEASE_STATE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment