-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
343 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,276 @@ | ||
name: Generate Zip | ||
|
||
on: | ||
workflow_call: | ||
secrets: | ||
COMPOSER_TOKEN: | ||
description: 'Composer token' | ||
required: false | ||
NODE_AUTH_TOKEN: | ||
description: 'Node auth token' | ||
required: false | ||
GH_BOT_TOKEN: | ||
description: 'GitHub Bot Token' | ||
required: true | ||
JENKINS_SECRET: | ||
description: 'Jenkins token for packaging requests' | ||
required: true | ||
S3_BUCKET: | ||
description: 'S3 bucket to place packaged zips' | ||
required: true | ||
S3_ACCESS_KEY_ID: | ||
description: 'S3 access key ID' | ||
required: true | ||
S3_SECRET_ACCESS_KEY: | ||
description: 'S3 Secret Access Key' | ||
required: true | ||
S3_REGION: | ||
description: 'S3 Region' | ||
required: true | ||
S3_ENDPOINT: | ||
description: 'S3 Endpoint' | ||
required: true | ||
inputs: | ||
ref: | ||
description: 'Git Commit Ref (branch, tag, or hash)' | ||
default: 'main' | ||
required: true | ||
type: string | ||
production: | ||
description: 'Is this a production build?' | ||
default: 'no' | ||
required: false | ||
type: string | ||
php_version: | ||
description: 'PHP version to use' | ||
default: '7.4' | ||
required: false | ||
type: string | ||
i18n: | ||
description: 'Perform pup i18n steps' | ||
default: 'yes' | ||
required: false | ||
type: string | ||
check: | ||
description: 'Perform pup check steps' | ||
default: 'yes' | ||
required: false | ||
type: string | ||
additional_commands: | ||
description: 'Execute additional commands' | ||
default: '' | ||
required: false | ||
type: string | ||
slack_channel: | ||
description: 'Slack channel ID to post to' | ||
required: false | ||
type: string | ||
slack_thread: | ||
description: 'Slack thread to post to' | ||
required: false | ||
type: string | ||
|
||
jobs: | ||
generate-zip: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# ------------------------------------------------------------------------------ | ||
# Checkout the repo. | ||
# ------------------------------------------------------------------------------ | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
token: ${{ secrets.GH_BOT_TOKEN }} | ||
submodules: recursive | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Setup Node. | ||
# ------------------------------------------------------------------------------ | ||
- name: Check for .nvmrc file | ||
id: check-nvmrc | ||
run: | | ||
if [ -f .nvmrc ]; then | ||
echo "exists=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "exists=false" >> $GITHUB_OUTPUT | ||
fi | ||
- uses: actions/setup-node@v4 | ||
if: steps.check-nvmrc.outputs.exists == 'true' | ||
with: | ||
node-version-file: '.nvmrc' | ||
cache: 'npm' | ||
|
||
- name: Set up authentication for NODE_AUTH_TOKEN if present | ||
run: | | ||
if [ -n "${{ secrets.NODE_AUTH_TOKEN }}" ]; then | ||
echo "//npm.pkg.github.com/:_authToken=${{ secrets.NODE_AUTH_TOKEN }}" >> ~/.npmrc | ||
fi | ||
# ------------------------------------------------------------------------------ | ||
# Setup bun. | ||
# ------------------------------------------------------------------------------ | ||
- name: Setup bun | ||
uses: oven-sh/setup-bun@v2 | ||
with: | ||
bun-version: latest | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Setup PHP. | ||
# ------------------------------------------------------------------------------ | ||
- name: Configure PHP environment | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ inputs.php_version }} | ||
extensions: mbstring, intl | ||
coverage: none | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Setup WordPress. | ||
# ------------------------------------------------------------------------------ | ||
- name: Set up WP-CLI | ||
run: | | ||
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | ||
chmod +x wp-cli.phar | ||
sudo mv wp-cli.phar /usr/local/bin/wp | ||
# ------------------------------------------------------------------------------ | ||
# Pup and filename setup. | ||
# ------------------------------------------------------------------------------ | ||
- name: install pup | ||
run: composer -- pup | ||
|
||
- name: get version | ||
if: ${{ inputs.production == 'yes' }} | ||
run: echo "VERSION=$(composer -- pup get-version)" >> $GITHUB_ENV | ||
|
||
- name: get dev version | ||
if: ${{ inputs.production == 'no' }} | ||
run: echo "VERSION=$(composer -- pup get-version --dev)" >> $GITHUB_ENV | ||
|
||
- name: get zip name | ||
run: echo "ZIP_NAME=$(composer -- pup zip-name ${{ env.VERSION }})" >> $GITHUB_ENV | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Try to find zip on s3 service. | ||
# ------------------------------------------------------------------------------ | ||
- name: Check if zip already exists | ||
uses: the-events-calendar/action-s3-utility@main | ||
if: ${{ inputs.production == 'no' }} | ||
id: s3_zip_exists | ||
continue-on-error: true | ||
env: | ||
S3_BUCKET: ${{ secrets.S3_BUCKET }} | ||
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} | ||
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} | ||
S3_REGION: ${{ secrets.S3_REGION }} | ||
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} | ||
COMMAND: exists | ||
FILE: "${{ env.ZIP_NAME }}.zip" | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Prepare our cache directories. | ||
# ------------------------------------------------------------------------------ | ||
- name: Get Composer Cache Directory | ||
if: steps.s3_zip_exists.outcome != 'success' | ||
id: get_composer_cache_dir | ||
run: | | ||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
- uses: actions/cache@v4 | ||
if: steps.s3_zip_exists.outcome != 'success' | ||
id: composer_cache | ||
with: | ||
path: ${{ steps.get_composer_cache_dir.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-composer- | ||
# ------------------------------------------------------------------------------ | ||
# Build and zip. | ||
# ------------------------------------------------------------------------------ | ||
- name: Determine if COMPOSER_TOKEN was provided | ||
run: | | ||
if [ -z "${{ secrets.COMPOSER_TOKEN }}" ]; then | ||
echo "COMPOSER_TOKEN_AVAILABLE=false" >> $GITHUB_ENV | ||
else | ||
echo "COMPOSER_TOKEN_AVAILABLE=true" >> $GITHUB_ENV | ||
fi | ||
- name: pup build | ||
if: steps.s3_zip_exists.outcome != 'success' | ||
run: composer -- pup build | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} | ||
|
||
- name: pup build with composer auth | ||
if: steps.s3_zip_exists.outcome != 'success' && env.COMPOSER_TOKEN_AVAILABLE == 'true' | ||
env: | ||
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.COMPOSER_TOKEN }}"}}' | ||
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} | ||
run: composer -- pup build | ||
|
||
- name: pup check | ||
if: steps.s3_zip_exists.outcome != 'success' && inputs.production == 'yes' && inputs.check == 'yes' | ||
run: composer -- pup check | ||
|
||
- name: Run additional_commands | ||
if: steps.s3_zip_exists.outcome != 'success' && inputs.additional_commands != '' | ||
run: ${{ inputs.additional_commands }} | ||
|
||
- name: pup i18n | ||
if: steps.s3_zip_exists.outcome != 'success' && inputs.i18n == 'yes' | ||
run: composer -- pup i18n | ||
|
||
- name: pup package | ||
id: pup_package | ||
if: steps.s3_zip_exists.outcome != 'success' | ||
run: composer -- pup package ${{ env.VERSION }} | ||
|
||
- name: Create the zip_files folder | ||
if: steps.s3_zip_exists.outcome != 'success' | ||
run: | | ||
mkdir zip_files | ||
cp ${{ env.ZIP_NAME }}.zip zip_files | ||
# ------------------------------------------------------------------------------ | ||
# Store zip on s3 service. | ||
# ------------------------------------------------------------------------------ | ||
- name: Upload the zip to Wasabi | ||
if: steps.s3_zip_exists.outcome != 'success' | ||
uses: the-events-calendar/action-s3-utility@main | ||
with: | ||
args: --acl public-read --follow-symlinks | ||
env: | ||
S3_BUCKET: ${{ secrets.S3_BUCKET }} | ||
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} | ||
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} | ||
S3_REGION: ${{ secrets.S3_REGION }} | ||
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} | ||
COMMAND: sync | ||
SOURCE_DIR: zip_files | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Update PR with zip info | ||
# ------------------------------------------------------------------------------ | ||
- name: Update PR with zip info | ||
if: github.event_name == 'pull_request' | ||
uses: ./.github/workflows/update-pr-with-zip.yml | ||
with: | ||
zip_name: ${{ env.ZIP_NAME }} | ||
secrets: inherit | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Send slack message. | ||
# ------------------------------------------------------------------------------ | ||
- name: Trigger Slack message | ||
if: inputs.slack_channel && inputs.slack_thread | ||
run: | | ||
curl -X GET "https://utility.theeventscalendar.com/slack-message.php?channel=${{ inputs.slack_channel }}&thread=${{ inputs.slack_thread }}&file=${{ env.ZIP_NAME }}.zip&secret=${{ secrets.JENKINS_SECRET }}&url=https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | ||
# ------------------------------------------------------------------------------ | ||
# Upload the artifact if it is a workflow dispatch. | ||
# ------------------------------------------------------------------------------ | ||
- name: Upload plugin artifact | ||
if: steps.pup_package.outcome == 'success' && github.event_name == 'workflow_dispatch' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ env.ZIP_NAME }} | ||
path: .pup-zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
zip_name: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
update_pr: | ||
if: github.event_name == 'pull_request' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Create WordPress Playground URL | ||
id: create_playground_url | ||
run: | | ||
# Base64 encode the blueprint JSON | ||
BLUEPRINT=$(echo '{ | ||
"preferredVersions": { | ||
"php": "8.0", | ||
"wp": "latest" | ||
}, | ||
"steps": [ | ||
{ | ||
"step": "installPlugin", | ||
"pluginData": { | ||
"resource": "url", | ||
"url": "https://evnt.is/test.zip?file=${{ inputs.zip_name }}.zip" | ||
}, | ||
"options": { | ||
"activate": true | ||
} | ||
}, | ||
{ | ||
"step": "installTheme", | ||
"themeData": { | ||
"resource": "wordpress.org/themes", | ||
"slug": "kadence" | ||
}, | ||
"options": { | ||
"activate": true | ||
} | ||
} | ||
] | ||
}' | base64 -w 0) | ||
# Create the playground URL | ||
PLAYGROUND_URL="https://playground.wordpress.net/#${BLUEPRINT}" | ||
# Set output | ||
echo "url=$PLAYGROUND_URL" >> $GITHUB_OUTPUT | ||
- name: Add PR comment | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const zipUrl = 'https://evnt.is/test.zip?file=${{ inputs.zip_name }}.zip'; | ||
const playgroundUrl = '${{ steps.create_playground_url.outputs.url }}'; | ||
await github.rest.issues.createComment({ | ||
...context.repo, | ||
issue_number: context.issue.number, | ||
body: `🎉 Build artifacts | ||
- Download zip: [${zipUrl}](${zipUrl}) | ||
- [Try it in WordPress Playground](${playgroundUrl})` | ||
}); |
Oops, something went wrong.