Port over, may not work
All checks were successful
Build & Release WordPress Plugin / build (push) Successful in 33s
All checks were successful
Build & Release WordPress Plugin / build (push) Successful in 33s
This commit is contained in:
parent
8635773bdd
commit
fa0b438a95
2 changed files with 117 additions and 0 deletions
90
.forgejo/workflows/wordpress-plugin.yml
Normal file
90
.forgejo/workflows/wordpress-plugin.yml
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
# 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:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: docker
|
||||||
|
container: debian:12
|
||||||
|
|
||||||
|
env:
|
||||||
|
SOURCE_DIR: "src"
|
||||||
|
|
||||||
|
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Prepare Build Environment
|
||||||
|
run: |
|
||||||
|
apt update && apt -y install zip nodejs curl jq
|
||||||
|
|
||||||
|
- name: Checkout repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Package plugin
|
||||||
|
run: |
|
||||||
|
# Set plugin name like this because it's easier than inline
|
||||||
|
PLUGIN_NAME=$(echo $GITHUB_REPOSITORY | awk -F'/' '{ print $2 }')
|
||||||
|
|
||||||
|
# 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
|
||||||
|
zip -r "${PLUGIN_NAME}.zip" "build/${PLUGIN_NAME}"
|
||||||
|
|
||||||
|
- name: Create Release if not exists
|
||||||
|
run: |
|
||||||
|
# Curl request that uses the repos token & Forgejo's built-in variables
|
||||||
|
# to create a new release based on the tag that you have pushed
|
||||||
|
#
|
||||||
|
# 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 }')
|
||||||
|
|
||||||
|
# Get the release ID created in the last step
|
||||||
|
RELEASE_ID=$(curl -s \
|
||||||
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||||
|
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG_NAME}" \
|
||||||
|
| 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?name=${PLUGIN_NAME}.zip" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||||
|
-H "Content-Type: application/zip" \
|
||||||
|
--data-binary "@build/${PLUGIN_NAME}.zip"
|
27
src/my-first-plugin.php
Normal file
27
src/my-first-plugin.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Plugin Name: My First Plugin
|
||||||
|
* Plugin URI: https://repobase.net/j/workflow-sample-wordpress-plugin
|
||||||
|
* Description: A simple "Hello World" plugin for WordPress.
|
||||||
|
* Version: 1.0.0
|
||||||
|
* Author: ChatGPT
|
||||||
|
* Author URI: https://repobase.net/j/workflow-sample-wordpress-plugin
|
||||||
|
* License: GPL2
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Prevent direct access
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hook into the admin dashboard
|
||||||
|
add_action( 'admin_notices', 'mfp_show_admin_notice' );
|
||||||
|
|
||||||
|
function mfp_show_admin_notice() {
|
||||||
|
?>
|
||||||
|
<div class="notice notice-success is-dismissible">
|
||||||
|
<p><?php _e( 'Hello World from My First Plugin!', 'my-first-plugin' ); ?></p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue