Skip to content

Commit

Permalink
Setup deployment for PHP packages (#48)
Browse files Browse the repository at this point in the history
* Setup deployment for PHP packages

* Create spicy-carpets-march.md

* Update release.yml

* Update changeset and changelog

* Update README.md
  • Loading branch information
irshadahmad21 authored Jan 24, 2024
1 parent 85c542c commit 78deae9
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/spotty-guests-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@wpsocio/telegram-format-text": major
"@wpsocio/wptelegram-bot-api": major
"@wpsocio/wp-utils": major
---

First public release.
93 changes: 93 additions & 0 deletions .github/workflows/deploy-php-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Deploy PHP Package

on:
release:
types: [published]

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
deploy:
name: Deploy PHP Package
needs: [details]
runs-on: ubuntu-latest
if: ${{ fromJson(needs.details.outputs.result).shouldDeploy }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./actions/setup
with:
lockfile: pnpm-hashed.lock

- name: Clean up
run: |
# Create a temp dir and move the files to it
mkdir -p temp/${{ fromJson(needs.details.outputs.result).path }}
# Move only the files that are needed
mv -t temp/${{ fromJson(needs.details.outputs.result).path }} composer.json src/ LICENSE README.md CHANGELOG.md .gitignore
- name: Deploy to repo
uses: manzoorwanijk/action-deploy-to-repo@v3
with:
src_dir: temp/${{ fromJson(needs.details.outputs.result).path }}
target_repo: ${{ fromJson(needs.details.outputs.result).repo }}
target_dir: "."
target_branch: main
access_token: ${{ secrets.GH_ACCESS_TOKEN }}
# Remove everything from the target repo before deploying
cleanup_command: git rm -rf . && git clean -fxd

- name: Release
uses: softprops/action-gh-release@v1
with:
body: ${{ github.event.release.body }}
token: ${{ secrets.GH_ACCESS_TOKEN }}
tag_name: v${{ fromJson(needs.details.outputs.result).version }}
repository: ${{ fromJson(needs.details.outputs.result).repo }}

details:
name: Get details
runs-on: ubuntu-latest
outputs:
result: ${{ steps.details.outputs.result }}
steps:
- name: Get details
uses: actions/github-script@v7
id: details
with:
script: |
const tagRegex = /^(?<name>.+)@(?<version>[^@]+)$/;
const result = '${{ github.event.release.tag_name }}'.match(tagRegex);
if (!result?.groups?.name || !result?.groups?.version) {
console.warn('Invalid tag name: "${{ github.event.release.tag_name }}"');
return { shouldDeploy: false };
}
const { name, version } = result.groups;
const toDeploy = [
'@wpsocio/telegram-format-text',
'@wpsocio/wp-utils',
'@wpsocio/wptelegram-bot-api',
];
if (!toDeploy.includes(name)) {
return { shouldDeploy: false };
}
const path = `packages/php/${name.split('/', 2)[1]}/`;
const shouldDeploy = true;
const repo = name.replace('@', '');
return { name, version, path, repo, shouldDeploy };
- name: Print details
run: |
echo "Details: ${{ steps.details.outputs.result }}"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy
name: Deploy WP Project

on:
release:
Expand All @@ -8,7 +8,7 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
deploy:
name: Deploy
name: Deploy WP Project
needs: [details]
runs-on: ubuntu-latest
if: ${{ fromJson(needs.details.outputs.result).shouldDeploy }}
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
const result = '${{ github.event.release.tag_name }}'.match(tagRegex);
if (!result) {
if (!result?.groups?.name || !result?.groups?.version) {
console.warn('Invalid tag name: "${{ github.event.release.tag_name }}"');
return { shouldDeploy: false };
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Prepare or publish release
if: github.repository == 'irshadahmad21/wp-plugins-dev-test'
if: github.repository == 'wpsocio/wp-plugins-dev'
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
5 changes: 5 additions & 0 deletions packages/php/telegram-format-text/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.0.1

- Initial private release.
2 changes: 1 addition & 1 deletion packages/php/telegram-format-text/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wpsocio/telegram-format-text",
"version": "1.0.0",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions packages/php/wp-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.0.1

- Initial private release.
2 changes: 1 addition & 1 deletion packages/php/wp-utils/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wpsocio/wp-utils",
"description": "Easy solution to handle WP plugin or theme options",
"description": "Utilities for WordPress plugins and themes",
"type": "library",
"license": "GPL-3.0-or-later",
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion packages/php/wp-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wpsocio/wp-utils",
"version": "1.0.0",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions packages/php/wptelegram-bot-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.0.1

- Initial private release.
2 changes: 1 addition & 1 deletion packages/php/wptelegram-bot-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wpsocio/wptelegram-bot-api",
"version": "1.0.0",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion tools/vite-wp-react/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @wpsocio/vite-wp-react

Set of tools to develop WordPress plugins and themes using React and Vite. It can be used along with `WPSocio\WPUtils\ViteWPReactAssets` from `wpsocio/wp-utils` composer package.
Set of tools to develop WordPress plugins and themes using React and Vite. It can be used along with `WPSocio\WPUtils\ViteWPReactAssets` from [`wpsocio/wp-utils`](https://packagist.org/packages/wpsocio/wp-utils) composer package.

## Usage

Expand Down

0 comments on commit 78deae9

Please sign in to comment.