feature-testing #3

Merged
j merged 2 commits from feature-testing into main 2025-06-17 16:35:04 +10:00
Showing only changes of commit ddfd175650 - Show all commits

View file

@ -1,45 +1,94 @@
name: Build Plugin Zip # Building and releasing Wordpress plugins is pretty simple
# It's just zipping up some PHP. This doesn't contain any unit tests
# this is just zipping and shipping.
#
# Generally speaking your directory structure would be:
# .
# ├── README.md
# └── src
# └── wordpress-plugin.php
#
# With the repository name being the name of your plugin to make it easier
# to Google for. Up to you though; you can configure the source dir below.
#
# When you tag a commit and the tag stats with 'v', this workflow will
# zip and ship the Wordpress plugin to the 'releases' tab of Github or Forgejo
name: Build & Release WordPress Plugin
on: on:
push: push:
branches: tags:
- main - 'v*'
workflow_dispatch: # Manual trigger
jobs: jobs:
build-zip: build:
runs-on: docker runs-on: docker
container: debian:12
env:
SOURCE_DIR: "src"
steps: steps:
- name: Prepare Build Environment
run: |
apt update && apt -y install zip unzip nodejs curl jq
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Get repo name - name: Package plugin
id: repo_name
run: echo "REPO_NAME=$(basename $(git rev-parse --show-toplevel))" >> $GITHUB_ENV
- name: Prepare zip folder
run: | run: |
rm -rf /tmp/$REPO_NAME # Set plugin name like this because it's easier than inline
mkdir -p /tmp/$REPO_NAME PLUGIN_NAME=$(echo $GITHUB_REPOSITORY | awk -F'/' '{ print $2 }')
cp -r ./src/* /tmp/$REPO_NAME/
- name: Create zip archive # Create a build directory to ensure that we're correctly creating
# a single child directory in the zip.
mkdir -p build
cp -r ${SOURCE_DIR} "build/${PLUGIN_NAME}"
# Zip it up for shipping
cd build
zip -r "../${PLUGIN_NAME}.zip" "${PLUGIN_NAME}"
cd -
unzip -l "${PLUGIN_NAME}.zip"
- name: Create Release if not exists
run: | run: |
apt update && apt -y install zip # Curl request that uses the repos token & Forgejo's built-in variables
cd /tmp # to create a new release based on the tag that you have pushed
zip -r $REPO_NAME.zip $REPO_NAME #
# It doesn't care if the release exists or not.
curl -X POST "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases" \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "'"${GITHUB_REF##*/}"'",
"target_commitish": "main",
"name": "'"${GITHUB_REF##*/}"'",
"body": "Auto release",
"draft": false,
"prerelease": false
}' || true
- name: Upload Plugin Zip to Release
run: |
# Set some variables because it's cleaner than in-line
TAG_NAME="${GITHUB_REF##*/}"
REPO_NAME="$(basename $GITHUB_REPOSITORY)"
PLUGIN_NAME=$(echo $GITHUB_REPOSITORY | awk -F'/' '{ print $2 }')
- name: Upload zip artifact # Get the release ID created in the last step
uses: actions/upload-artifact@v3 RELEASE_ID=$(curl -s \
with: -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
name: ${{ env.REPO_NAME }}-plugin-zip "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG_NAME}" \
path: /tmp/${{ env.REPO_NAME }}.zip | jq -r '.id')
# Pushes he zip file to be shown in the "Releases" tab under this release.
curl -X POST "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets" \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-F "name=${PLUGIN_NAME}.zip" \
-F "attachment=@${PLUGIN_NAME}.zip"
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: build/${{ env.REPO_NAME }}.zip
asset_name: ${{ env.REPO_NAME }}.zip
asset_content_type: application/zip