Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate reusable parts of workflow into an action #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/actions/update-plugin/action.yml
Original file line number Diff line number Diff line change
@@ -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 [email protected]

# 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/[email protected]
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
4 changes: 4 additions & 0 deletions .github/actions/update-plugin/check.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
require_once './vendor/autoload.php';
$pack = new Max_WP_Package('package.zip');
echo $pack->get_metadata()['version'];
71 changes: 7 additions & 64 deletions .github/workflows/examples/events-calendar-pro.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Updater
name: The Events Calendar Updater

# Run this workflow twice daily
on:
on:
# schedule:
# - cron: '0 */12 * * *'
workflow_dispatch:
Expand All @@ -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:
Expand All @@ -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 [email protected]

- 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/[email protected]
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
69 changes: 6 additions & 63 deletions .github/workflows/examples/facetwp.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Updater
name: FacetWP Updater

# Run this workflow twice daily
on:
Expand All @@ -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:
Expand All @@ -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 [email protected]

- 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/[email protected]
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
80 changes: 8 additions & 72 deletions .github/workflows/examples/gravityforms.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Updater
name: Gravity Forms Updater

# Run this workflow twice daily
on:
on:
# schedule:
# - cron: '0 */12 * * *'
workflow_dispatch:
Expand All @@ -10,93 +10,29 @@ 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:
- name: Checkout repo
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
uses: fjogeleit/http-request-action@master
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 [email protected]

- 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/[email protected]
# 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
Loading