-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 changed file
with
171 additions
and
0 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,171 @@ | ||
name: Generate Zip | ||
|
||
on: | ||
workflow_call: | ||
secrets: | ||
access-token: | ||
description: 'GitHub Access Token' | ||
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: false | ||
type: boolean | ||
i18n: | ||
description: 'Perform pup i18n steps' | ||
default: true | ||
type: boolean | ||
check: | ||
description: 'Perform pup check steps' | ||
default: true | ||
type: boolean | ||
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 | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Prepare job variables. | ||
# ------------------------------------------------------------------------------ | ||
- name: Prepare job variables | ||
run: | | ||
echo "JOB_REF=${{ inputs.ref }}" >> $GITHUB_ENV | ||
echo "branch=${JOB_REF}" >> $GITHUB_OUTPUT | ||
# ------------------------------------------------------------------------------ | ||
# Pup and filename setup. | ||
# ------------------------------------------------------------------------------ | ||
- name: install pup | ||
run: composer -- pup | ||
|
||
- name: get version | ||
if: inputs.production | ||
run: echo "VERSION=$(composer -- pup get-version)" >> $GITHUB_ENV | ||
|
||
- name: get dev version | ||
if: ${{ !inputs.production }} | ||
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 }} | ||
id: s3_zip_exists | ||
continue-on-error: true | ||
env: | ||
S3_BUCKET: ${{ secrets.PACKAGED_ZIP_BUCKET }} | ||
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} | ||
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} | ||
S3_REGION: ${{ secrets.PACKAGED_ZIP_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@v2 | ||
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: pup build | ||
if: steps.s3_zip_exists.outcome != 'success' | ||
run: composer -- pup build | ||
|
||
- name: pup check | ||
if: steps.s3_zip_exists.outcome != 'success' && inputs.production && inputs.check | ||
run: composer -- pup check | ||
|
||
- name: pup i18n | ||
if: steps.s3_zip_exists.outcome != 'success' && inputs.i18n | ||
run: composer -- pup i18n | ||
|
||
- name: 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 | ||
- name: pup package | ||
id: pup_package | ||
if: steps.s3_zip_exists.outcome != 'success' | ||
run: composer -- pup package ${{ env.VERSION }} | ||
|
||
# ------------------------------------------------------------------------------ | ||
# 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.PACKAGED_ZIP_BUCKET }} | ||
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} | ||
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} | ||
S3_REGION: ${{ secrets.PACKAGED_ZIP_REGION }} | ||
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} | ||
COMMAND: sync | ||
SOURCE_DIR: zip_files | ||
|
||
# ------------------------------------------------------------------------------ | ||
# 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.SLACK_PACKAGING_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@v3 | ||
with: | ||
name: ${{ env.ZIP_NAME }} | ||
path: .pup-zip |