diff --git a/.github/actions/update-plugin/action.yml b/.github/actions/update-plugin/action.yml new file mode 100644 index 0000000..78a230e --- /dev/null +++ b/.github/actions/update-plugin/action.yml @@ -0,0 +1,89 @@ +name: 'Update WordPress Plugin' +description: 'Download and compare versions of a WordPress plugin, commit the latest version' + +inputs: + + # The slug of the plugin to update + package-slug: + description: 'The slug of the plugin to update' + required: true + + # Package file name + package-file-name: + description: 'Package file name' + required: true + +runs: + using: 'composite' + steps: + + # Set up PHP + - name: 'Setup PHP' + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + + # Install composer dependencies + - name: Composer + shell: bash + run: 'composer install' + + # Get the current plugin version + - name: 'Get Previous tag' + id: previous_version + uses: "WyriHaximus/github-action-get-previous-tag@v1" + + # Get new plugin version + - name: 'Get version' + id: new_version + shell: bash + run: echo "new_version=$(php .github/actions/update-plugin/check.php)" >> $GITHUB_OUTPUT + + # Configure git user + - name: 'Git config' + if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} + shell: bash + run: | + git config user.name "GitHub Actions" + git config user.email noreply@github.com + + # Compare versions + - name: 'Clean' + if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} + shell: bash + run: find . -maxdepth 1 \( -name 'package.zip' -o -name 'composer.json' -o -name 'composer.lock' -o -name '.gitignore' -o -path './.git' -o -path './.github' \) -prune -o -exec rm -rf {} \; + + # Unzip the package + - name: Unzip + if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} + uses: TonyBogdanov/zip@1.0 + with: + args: unzip -qq ./package.zip -d . + + # You may not need this step depending on the contents of the zip + - name: Move + if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} + shell: bash + run: shopt -s dotglob && sudo mv ${{ env.PACKAGE_SLUG }}/* . + + - name: rm + if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} + shell: bash + run: rm package.zip && rm -rf ${{ env.PACKAGE_SLUG }} + + - name: Commit + if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} + id: make-commit + shell: bash + run: | + git add . + git commit -m '${{ steps.new_version.outputs.new_version }}' + echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + + - name: Push + if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} + shell: bash + run: | + git push + git tag ${{ steps.new_version.outputs.new_version }} + git push --tags diff --git a/.github/actions/update-plugin/check.php b/.github/actions/update-plugin/check.php new file mode 100644 index 0000000..593fbcd --- /dev/null +++ b/.github/actions/update-plugin/check.php @@ -0,0 +1,4 @@ +get_metadata()['version']; diff --git a/.github/workflows/examples/events-calendar-pro.yml b/.github/workflows/examples/events-calendar-pro.yml index 388973e..c9dd52f 100644 --- a/.github/workflows/examples/events-calendar-pro.yml +++ b/.github/workflows/examples/events-calendar-pro.yml @@ -1,7 +1,7 @@ -name: Updater +name: The Events Calendar Updater # Run this workflow twice daily -on: +on: # schedule: # - cron: '0 */12 * * *' workflow_dispatch: @@ -10,12 +10,8 @@ env: PACKAGE_SLUG: events-calendar-pro jobs: - # Set the job key. The key is displayed as the job name - # when a job name is not provided update: - # Name the Job name: Fetch and check versions - # Set the type of machine to run on runs-on: ubuntu-latest steps: @@ -28,62 +24,9 @@ jobs: - name: Fetch run: wget 'https://pue.tri.be/api/plugins/v2/download?plugin=events-calendar-pro&key=${{secrets.TEC_KEY}}' -O package.zip - # PHP - - name: 'Setup PHP' - uses: shivammathur/setup-php@v2 + # Get the latest plugin and compare versions, commit if necessary + - uses: ./.github/actions/update-plugin + name: Update WordPress Plugin with: - php-version: '8.0' - - # Install dependencies - - name: Composer - run: 'composer install' - - # Get current tag - - name: 'Get Previous tag' - id: previous_version - uses: "WyriHaximus/github-action-get-previous-tag@v1" - - # Get new version - - name: 'Get version' - id: new_version - run: echo "new_version=$(php .github/workflows/check.php)" >> $GITHUB_OUTPUT - - - name: 'Git config' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git config user.name "GitHub Actions" - git config user.email noreply@github.com - - - name: 'Clean' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: find . -maxdepth 1 \( -name 'README.md' -o -name 'package.zip' -o -name 'composer.json' -o -name 'composer.lock' -o -name '.gitignore' -o -path './.git' -o -path './.github' \) -prune -o -exec rm -rf {} \; - - - name: Unzip - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - uses: TonyBogdanov/zip@1.0 - with: - args: unzip -qq ./package.zip -d . - - # You may not need this step depending on the contents of the zip - - name: Move - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: shopt -s dotglob && sudo mv ${{ env.PACKAGE_SLUG }}/* . - - - name: rm - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: rm package.zip && rm -rf ${{ env.PACKAGE_SLUG }} - - - name: Commit - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - id: make-commit - run: | - git add . - git commit -m '${{ steps.new_version.outputs.new_version }}' - echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - - name: Push - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git push - git tag ${{ steps.new_version.outputs.new_version }} - git push --tags + package-slug: ${{ env.PACKAGE_SLUG }} + package-file-name: package.zip diff --git a/.github/workflows/examples/facetwp.yml b/.github/workflows/examples/facetwp.yml index 0cb518c..ced3686 100644 --- a/.github/workflows/examples/facetwp.yml +++ b/.github/workflows/examples/facetwp.yml @@ -1,4 +1,4 @@ -name: Updater +name: FacetWP Updater # Run this workflow twice daily on: @@ -10,12 +10,8 @@ env: PACKAGE_SLUG: facetwp jobs: - # Set the job key. The key is displayed as the job name - # when a job name is not provided update: - # Name the Job name: Fetch and check versions - # Set the type of machine to run on runs-on: ubuntu-latest steps: @@ -42,62 +38,9 @@ jobs: - name: Fetch run: wget '${{fromJson(steps.FacetWPAPIResponse.outputs.response).slugs[env.PACKAGE_SLUG].package}}' -O package.zip - # PHP - - name: 'Setup PHP' - uses: shivammathur/setup-php@v2 + # Get the latest plugin and compare versions, commit if necessary + - uses: ./.github/actions/update-plugin + name: Update WordPress Plugin with: - php-version: '8.0' - - # Install dependencies - - name: Composer - run: 'composer install' - - # Get current tag - - name: 'Get Previous tag' - id: previous_version - uses: "WyriHaximus/github-action-get-previous-tag@v1" - - # Get new version - - name: 'Get version' - id: new_version - run: echo "new_version=$(php .github/workflows/check.php)" >> $GITHUB_OUTPUT - - - name: 'Git config' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git config user.name "GitHub Actions" - git config user.email noreply@github.com - - - name: 'Clean' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: find . -maxdepth 1 \( -name 'package.zip' -o -name 'composer.json' -o -name 'composer.lock' -o -name '.gitignore' -o -path './.git' -o -path './.github' \) -prune -o -exec rm -rf {} \; - - - name: Unzip - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - uses: TonyBogdanov/zip@1.0 - with: - args: unzip -qq ./package.zip -d . - - # You may not need this step depending on the contents of the zip - - name: Move - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: shopt -s dotglob && sudo mv ${{ env.PACKAGE_SLUG }}/* . - - - name: rm - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: rm package.zip && rm -rf ${{ env.PACKAGE_SLUG }} - - - name: Commit - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - id: make-commit - run: | - git add . - git commit -m '${{ steps.new_version.outputs.new_version }}' - echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - - name: Push - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git push - git tag ${{ steps.new_version.outputs.new_version }} - git push --tags + package-slug: ${{ env.PACKAGE_SLUG }} + package-file-name: package.zip diff --git a/.github/workflows/examples/gravityforms.yml b/.github/workflows/examples/gravityforms.yml index 99bb512..36c9092 100644 --- a/.github/workflows/examples/gravityforms.yml +++ b/.github/workflows/examples/gravityforms.yml @@ -1,7 +1,7 @@ -name: Updater +name: Gravity Forms Updater # Run this workflow twice daily -on: +on: # schedule: # - cron: '0 */12 * * *' workflow_dispatch: @@ -10,12 +10,8 @@ env: PACKAGE_SLUG: gravityforms jobs: - # Set the job key. The key is displayed as the job name - # when a job name is not provided update: - # Name the Job name: Fetch and check versions - # Set the type of machine to run on runs-on: ubuntu-latest steps: @@ -23,7 +19,7 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 - + # Use GravityForms API to find download link for latest - name: Get download link from GravityForms API id: GravityFormsAPIResponse @@ -31,72 +27,12 @@ jobs: with: url: 'https://www.gravityhelp.com/wp-content/plugins/gravitymanager/version.php?nocache=1&version=2&key=${{secrets.GRAVITYFORMS_KEY}}' - # uncomment to debug or see other "offerings" your license can download - #- name: Show Response - # run: echo ${{ steps.GravityFormsAPIResponse.outputs.response }} - - # Fetch latest version of GravityForms to download - # Note: to access GravityForms add-ons/extensions change `offerings.gravityforms.url_latest` - # to e.g. `offerings.gravityformsmailchimp.url_latest` - name: Fetch run: wget '${{fromJson(steps.GravityFormsAPIResponse.outputs.response).offerings[env.PACKAGE_SLUG].url_latest}}' -O package.zip - - # PHP - - name: 'Setup PHP' - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - - # Install dependencies - - name: Composer - run: 'composer install' - - # Get current tag - - name: 'Get Previous tag' - id: previous_version - uses: "WyriHaximus/github-action-get-previous-tag@v1" - - # Get new version - - name: 'Get version' - id: new_version - run: echo "new_version=$(php .github/workflows/check.php)" >> $GITHUB_OUTPUT - - - name: 'Git config' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git config user.name "GitHub Actions" - git config user.email noreply@github.com - - - name: 'Clean' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: find . -maxdepth 1 \( -name 'package.zip' -o -name 'composer.json' -o -name 'composer.lock' -o -name '.gitignore' -o -path './.git' -o -path './.github' \) -prune -o -exec rm -rf {} \; - - name: Unzip - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - uses: TonyBogdanov/zip@1.0 + # Get the latest plugin and compare versions, commit if necessary + - uses: ./.github/actions/update-plugin + name: Update WordPress Plugin with: - args: unzip -qq ./package.zip -d . - - # You may not need this step depending on the contents of the zip - - name: Move - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: shopt -s dotglob && sudo mv ${{ env.PACKAGE_SLUG }}/* . - - - name: rm - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: rm package.zip && rm -rf ${{ env.PACKAGE_SLUG }} - - - name: Commit - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - id: make-commit - run: | - git add . - git commit -m '${{ steps.new_version.outputs.new_version }}' - echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - - name: Push - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git push - git tag ${{ steps.new_version.outputs.new_version }} - git push --tags + package-slug: ${{ env.PACKAGE_SLUG }} + package-file-name: package.zip diff --git a/.github/workflows/examples/gravityformsaddon.yml b/.github/workflows/examples/gravityformsaddon.yml index 4812cb1..6d6e24a 100644 --- a/.github/workflows/examples/gravityformsaddon.yml +++ b/.github/workflows/examples/gravityformsaddon.yml @@ -1,7 +1,7 @@ -name: Updater +name: Gravity Forms Addon Updater # Run this workflow twice daily -on: +on: # schedule: # - cron: '0 */12 * * *' workflow_dispatch: @@ -10,12 +10,8 @@ env: PACKAGE_SLUG: gravityformsrecaptcha jobs: - # Set the job key. The key is displayed as the job name - # when a job name is not provided update: - # Name the Job name: Fetch and check versions - # Set the type of machine to run on runs-on: ubuntu-latest steps: @@ -23,7 +19,7 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 - + # Use GravityForms API to find download link for latest - name: Get download link from GravityForms API id: GravityFormsAPIResponse @@ -31,70 +27,13 @@ jobs: with: url: 'https://www.gravityhelp.com/wp-content/plugins/gravitymanager/version.php?nocache=1&version=2&key=${{secrets.GRAVITYFORMS_KEY}}' - # uncomment to debug or see other "offerings" your license can download - #- name: Show Response - # run: echo ${{ steps.GravityFormsAPIResponse.outputs.response }} - # Fetch latest version of Gravity Forms add-on to download - name: Fetch run: wget '${{fromJson(steps.GravityFormsAPIResponse.outputs.response).offerings[env.PACKAGE_SLUG].url_latest}}' -O package.zip - - # PHP - - name: 'Setup PHP' - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - - # Install dependencies - - name: Composer - run: 'composer install' - - # Get current tag - - name: 'Get Previous tag' - id: previous_version - uses: "WyriHaximus/github-action-get-previous-tag@v1" - - # Get new version - - name: 'Get version' - id: new_version - run: echo "new_version=$(php .github/workflows/check.php)" >> $GITHUB_OUTPUT - - - name: 'Git config' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git config user.name "GitHub Actions" - git config user.email noreply@github.com - - - name: 'Clean' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: find . -maxdepth 1 \( -name 'package.zip' -o -name 'composer.json' -o -name 'composer.lock' -o -name '.gitignore' -o -path './.git' -o -path './.github' \) -prune -o -exec rm -rf {} \; - - name: Unzip - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - uses: TonyBogdanov/zip@1.0 + # Get the latest plugin and compare versions, commit if necessary + - uses: ./.github/actions/update-plugin + name: Update WordPress Plugin with: - args: unzip -qq ./package.zip -d . - - # You may not need this step depending on the contents of the zip - - name: Move - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: shopt -s dotglob && sudo mv ${{ env.PACKAGE_SLUG }}/* . - - - name: rm - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: rm package.zip && rm -rf ${{ env.PACKAGE_SLUG }} - - - name: Commit - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - id: make-commit - run: | - git add . - git commit -m '${{ steps.new_version.outputs.new_version }}' - echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - - name: Push - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git push - git tag ${{ steps.new_version.outputs.new_version }} - git push --tags + package-slug: ${{ env.PACKAGE_SLUG }} + package-file-name: package.zip diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index bd2dcfd..d4fc1af 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -1,13 +1,13 @@ -name: Updater +name: Example Plugin Updater # Run this workflow twice daily -on: +on: # schedule: # - cron: '0 */12 * * *' workflow_dispatch: env: - PACKAGE_SLUG: advanced-custom-fields-pro + PACKAGE_SLUG: example-plugin jobs: # Set the job key. The key is displayed as the job name @@ -28,62 +28,9 @@ jobs: - name: Fetch run: wget 'https://privateplugin.example&k=${{secrets.PLUGIN_KEY}}' -O package.zip - # PHP - - name: 'Setup PHP' - uses: shivammathur/setup-php@v2 + # Get the latest plugin and compare versions, commit if necessary + - uses: ./.github/actions/update-plugin + name: Update WordPress Plugin with: - php-version: '8.0' - - # Install dependencies - - name: Composer - run: 'composer install' - - # Get current tag - - name: 'Get Previous tag' - id: previous_version - uses: "WyriHaximus/github-action-get-previous-tag@v1" - - # Get new version - - name: 'Get version' - id: new_version - run: echo "new_version=$(php .github/workflows/check.php)" >> $GITHUB_OUTPUT - - - name: 'Git config' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git config user.name "GitHub Actions" - git config user.email noreply@github.com - - - name: 'Clean' - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: find . -maxdepth 1 \( -name 'package.zip' -o -name 'composer.json' -o -name 'composer.lock' -o -name '.gitignore' -o -path './.git' -o -path './.github' \) -prune -o -exec rm -rf {} \; - - - name: Unzip - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - uses: TonyBogdanov/zip@1.0 - with: - args: unzip -qq ./package.zip -d . - - # You may not need this step depending on the contents of the zip - - name: Move - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: shopt -s dotglob && sudo mv ${{ env.PACKAGE_SLUG }}/* . - - - name: rm - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: rm package.zip && rm -rf ${{ env.PACKAGE_SLUG }} - - - name: Commit - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - id: make-commit - run: | - git add . - git commit -m '${{ steps.new_version.outputs.new_version }}' - echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - - name: Push - if: ${{ steps.previous_version.outputs.tag != steps.new_version.outputs.new_version }} - run: | - git push - git tag ${{ steps.new_version.outputs.new_version }} - git push --tags + package-slug: ${{ env.PACKAGE_SLUG }} + package-file-name: package.zip