├── Dockerfile ├── README.md ├── action.yml └── deploy.php /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4-cli 2 | 3 | # install git 4 | RUN apt-get update 5 | RUN apt-get install -y git 6 | 7 | 8 | ARG file_name 9 | ARG version 10 | ARG sandbox 11 | ARG release_mode 12 | 13 | COPY deploy.php /deploy.php 14 | COPY ${file_name} /${file_name} 15 | RUN git clone https://github.com/Freemius/freemius-php-sdk.git /freemius-php-api 16 | 17 | EXPOSE 80/tcp 18 | EXPOSE 80/udp 19 | 20 | CMD php /deploy.php -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Freemius Deploy 2 | 3 | This Github Action deploys your wordpress plugin on Freemius. It uses the [Freemius PHP SDK](https://github.com/Freemius/freemius-php-sdk.git) and uses some of the functionality of [CodeAtCode/freemius-suite](https://github.com/CodeAtCode/freemius-suite) 4 | 5 | ## Arguments 6 | 7 | | Argument | Required | Function | Default | 8 | | -------------- | -------- | ------- | ------- | 9 | | `file_name` | Yes | File name of the to be uploaded wordpress plugin (zip extension). _Note: the file has to be in the root folder of your repository_ | | 10 | | `release_mode` | No | `pending`, `beta`, or `released`. Set to beta to release the product to valid license holders that opted into the beta list. Set to released to release it to all valid license holders. When the product is released, it will be available for download right within the WP Admin dashboard. | `pending` | 11 | | `version` | Yes | This is used to check whether the release is already uploaded. **Action will fail if the release has already been uploaded** | | 12 | | `sandbox` | No | Whether to upload in sandbox mode | `false` | 13 | 14 | ## Environment variables 15 | 16 | **Required**: 17 | 18 | - `PUBLIC_KEY` 19 | - `DEV_ID` 20 | - `SECRET_KEY` 21 | - `PLUGIN_SLUG` 22 | - `PLUGIN_ID` 23 | 24 | All these are found in your Freemius dashboard. 25 | 26 | _Tip: store these variables in your [secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets)_ 27 | 28 | ## Action outputs (since v0.1.1) 29 | 30 | The action downloads both the **free** and **pro** version and outputs their filenames as outputs: 31 | 32 | - free_version 33 | - pro_version 34 | 35 | You can access these by setting an **id** to your workflow step. Consequently you can upload these as artifacts, or upload them to the wordpress svn repository, for example with [yukihiko-shinoda/action-deploy-wordpress-plugin](https://github.com/yukihiko-shinoda/action-deploy-wordpress-plugin). 36 | 37 | ## Example 38 | 39 | ```yml 40 | - name: Deploy to Freemius 41 | uses: buttonizer/freemius-deploy@v0.1.2 42 | with: 43 | file_name: my_wordpress_plugin.zip 44 | release_mode: pending 45 | version: 1.1.0 46 | sandbox: false 47 | env: 48 | PUBLIC_KEY: ${{ secrets.FREEMIUS_PUBLIC_KEY }} 49 | DEV_ID: 1234 50 | SECRET_KEY: ${{ secrets.FREEMIUS_SECRET_KEY }} 51 | PLUGIN_SLUG: my-wordpress-plugin 52 | PLUGIN_ID: 4321 53 | ``` 54 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Deploy on Freemius" 2 | description: "Uploads and deploys your plugin on Freemius" 3 | inputs: 4 | sandbox: 5 | description: 'Sandbox mode' 6 | required: false 7 | default: false 8 | file_name: 9 | description: 'file to deploy' 10 | required: true 11 | version: 12 | description: 'tag version' 13 | required: true 14 | release_mode: 15 | description: 'release mode' 16 | required: false 17 | default: 'pending' 18 | outputs: 19 | free_version: 20 | description: 'The Free version file' 21 | pro_version: 22 | description: 'The Pro version file' 23 | runs: 24 | using: 'docker' 25 | image: 'Dockerfile' 26 | branding: 27 | icon: 'arrow-up-circle' 28 | color: 'green' 29 | -------------------------------------------------------------------------------- /deploy.php: -------------------------------------------------------------------------------- 1 | Api('plugins/'.$_ENV['PLUGIN_ID'].'/tags.json', 'GET'); 31 | if ( $deploy->tags[0]->version === $version ) { 32 | $deploy = $deploy->tags[0]; 33 | echo '-Package already deployed on Freemius'."\n"; 34 | } else { 35 | // Upload the zip 36 | $deploy = $api->Api('plugins/'.$_ENV['PLUGIN_ID'].'/tags.json', 'POST', array( 37 | 'add_contributor' => false 38 | ), array( 39 | 'file' => $file_name 40 | )); 41 | 42 | if (!property_exists($deploy, 'id')) { 43 | print_r($deploy); 44 | die(); 45 | } 46 | 47 | echo "- Deploy done on Freemius\n"; 48 | 49 | $is_released = $api->Api('plugins/'.$_ENV['PLUGIN_ID'].'/tags/'.$deploy->id.'.json', 'PUT', array( 50 | 'release_mode' => $release_mode 51 | ), array()); 52 | 53 | echo "- Set as released on Freemius\n"; 54 | } 55 | 56 | echo "- Download Freemius free version\n"; 57 | 58 | // Generate url to download the zip 59 | $zip_free = $api->GetSignedUrl('plugins/'.$_ENV['PLUGIN_ID'].'/tags/'.$deploy->id.'.zip', array()); 60 | $path = pathinfo($file_name); 61 | $zipname_free = $path['dirname'] . '/' . basename($file_name, '.zip'); 62 | $zipname_free .= '__free.zip'; 63 | 64 | file_put_contents($zipname_free,file_get_contents($zip_free)); 65 | 66 | echo "- Downloaded Freemius free version to ".$zipname_free."\n"; 67 | echo "::set-output name=free_version::" . $zipname_free . "\n"; 68 | 69 | // Generate url to download the pro zip 70 | $zip_pro = $api->GetSignedUrl('plugins/'.$_ENV['PLUGIN_ID'].'/tags/'.$deploy->id.'.zip?is_premium=true', array()); 71 | $path = pathinfo($file_name); 72 | $zipname_pro = $path['dirname'] . '/' . basename($file_name, '.zip'); 73 | $zipname_pro .= '.zip'; 74 | 75 | file_put_contents($zipname_pro,file_get_contents($zip_pro)); 76 | 77 | echo "- Downloaded Freemius pro version to ".$zipname_pro."\n"; 78 | echo "::set-output name=pro_version::" . $zipname_pro . "\n"; 79 | } 80 | catch (Exception $e) { 81 | echo "- Freemius server has problems\n"; 82 | } 83 | --------------------------------------------------------------------------------