Skip to content

Instantly share code, notes, and snippets.

@afragen
Last active April 16, 2025 17:13
Show Gist options
  • Save afragen/0d1211d0fd4e61098b031b0befc27ef1 to your computer and use it in GitHub Desktop.
Save afragen/0d1211d0fd4e61098b031b0befc27ef1 to your computer and use it in GitHub Desktop.
Various GitHub Action workflows

These are most of the GitHub Action workflows that I use in my plugins.

I have included a .gitattributes file too. For those who don't know, a .gitattributes file using export-ignore will remove those files/folders designated from any download or zip export. This is very handy with or without a build process.

releases.yml includes the generation of a build-attestation-provenance for security.

* text=auto
.gitattributes export-ignore
.gitignore export-ignore
.editorconfig export-ignore
composer.lock export-ignore
phpunit.xml export-ignore
phpcs.xml export-ignore
phpcs.xml.dist export-ignore
.phpcs.xml export-ignore
/.github export-ignore
/bin export-ignore
/tests export-ignore
/wiki-assets export-ignore
name: Generate POT PR
on:
workflow_dispatch:
push:
branches:
- main
- master
jobs:
generate-pot:
name: Generate POT PR
if: github.repository == ${{ github.event.repository.full_name }}
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Set up PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
- name: Setup WP-CLI
uses: godaddy-wordpress/setup-wp-cli@1
- name: Configure git user
run: |
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
- name: Check if remote branch exists
run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin generate-pot) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
- name: Create branch to base pull request on
if: env.REMOTE_BRANCH_EXISTS == 0
run: |
git checkout -b generate-pot
- name: Fetch existing branch to add commits to
if: env.REMOTE_BRANCH_EXISTS == 1
run: |
git fetch --all --prune
git checkout generate-pot
git pull --no-rebase
- name: Generate POT
run: |
wp i18n make-pot . "./languages/${{ github.event.repository.name }}.pot" --headers='{"Report-Msgid-Bugs-To":"https://github.com/${{ github.event.repository.full_name }}/issues"}'
- name: Check if there are changes
run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
- name: Commit changes
if: env.CHANGES_DETECTED == 1
run: |
git add "./languages/${{ github.event.repository.name }}.pot"
git commit -s -m "Generate POT - $(date +'%Y-%m-%d')"
git push origin generate-pot
- name: Create pull request
if: env.CHANGES_DETECTED == 1 && env.REMOTE_BRANCH_EXISTS == 0
run: gh pr create --base ${BRANCH_NAME} --head generate-pot --title "Generate POT - $(date +'%Y-%m-%d')" --body "Automated PR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
name: Generate POT
on:
push:
branches:
- master
- main
jobs:
WP_POT_Generator:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@master
- name: WordPress POT Generator
uses: afragen/action-wp-pot-generator@main
with:
save_path: "./languages"
item_slug: "${{ github.event.repository.name }}"
domain: "${{ github.event.repository.name }}"
package_name: "${{ github.event.repository.name }}"
headers: '{"Report-Msgid-Bugs-To":"https://github.com/${{ github.event.repository.full_name }}/issues"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
push:
tags:
- "**"
name: Upload Release Asset
jobs:
build:
name: Upload Release Asset
runs-on: ubuntu-latest
permissions:
attestations: write
id-token: write
contents: write
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Get tag
id: tag
run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build project
run: git archive -o /tmp/${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.zip --prefix=${{ github.event.repository.name }}/ ${{ steps.tag.outputs.tag }}
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: /tmp/${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.zip
- name: Build provenance attestation
uses: actions/attest-build-provenance@v2
with:
subject-path: /tmp/${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.zip
# Based on https://github.com/wp-cli/scaffold-command/blob/f9bad3dd7224d5684d950d31c486df70905e386f/templates/plugin-github.mustache
# Thanks Josh https://github.com/Shelob9/wordpress-plugin/blob/main/.github/workflows/wordpress.yml
# Thanks https://github.com/shivammathur
# Thanks Alex Stine for rubber ducking and help figuring out MySQL 5.7
# Thanks @desrosj for idea to just use MySQL 8.0 with correct authentication method.
name: WordPress Tests
on:
push:
branches:
- develop
- master
- main
pull_request:
branches:
- develop
- master
- main
jobs:
run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]
name: PHP ${{ matrix.php-versions }} Test on ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Setup MySQL 8.0 with mysql_native_password
uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: "8.0"
my-cnf: |
bind_address=127.0.0.1
default-authentication-plugin=mysql_native_password
root-password: root
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
extensions: mysql, mysqli
tools: composer, wp-cli, phpunit-polyfills:1.1
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Composer install
run: composer install --optimize-autoloader --prefer-dist
- name: Install SVN
run: sudo apt-get update && sudo apt-get install -y subversion
- name: Install WP Tests
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 latest
- name: PHPUnit tests
run: |
echo "define('WP_TESTS_PHPUNIT_POLYFILLS_PATH', '$HOME/.composer/vendor/yoast/phpunit-polyfills');" >> /tmp/wordpress-tests-lib/wp-tests-config.php
phpunit --config=phpunit.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment