Skip to content

Commit

Permalink
Update cli and workflows (#36)
Browse files Browse the repository at this point in the history
* Update CLI to add support for changeset status

* Update config

* Fix schema

* Fix rollup build error by sticking to 4.9.5

* Fix version for rollup

* Update deps

* Delete changesets

* Update release.yml

* Update release.yml

* Rename to CHANGELOG

* Update deploy-to-svn.yml

* Update deploy-to-svn.yml

* Update deploy-to-svn.yml

* Add deploy to repo step

* Add clean up command to deploy to repo

* Deploy changelog and readme to repo

* Fix command

* Update deploy.yml

* Add widget readme

* Update deploy.yml

* Update deploy.yml

* Update deploy.yml

* Add changeset to wptelegram

* Create composite setup action

* Checkout before run

* Add shell to run steps

* enable-wireit-cache
  • Loading branch information
irshadahmad21 authored Jan 22, 2024
1 parent 972c27a commit 7b30e81
Show file tree
Hide file tree
Showing 35 changed files with 525 additions and 1,831 deletions.
5 changes: 0 additions & 5 deletions .changeset/beige-steaks-turn.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/breezy-sloths-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wptelegram": patch
---

Fixed the emojis in notifications not being sent.
6 changes: 5 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "wpsocio/wp-plugins-dev" }
{ "repo": "irshadahmad21/wp-plugins-dev-test" }
],
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"privatePackages": {
"tag": true,
"version": true
},
"ignore": []
}
6 changes: 0 additions & 6 deletions .changeset/plenty-years-jam.md

This file was deleted.

110 changes: 110 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Deploy

on:
release:
types: [published]

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

jobs:
tag:
name: New release
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
enable-wireit-cache: true

- name: Prepare bundle
run: |
pnpm wpdev bundle ${{ fromJson(needs.details.outputs.result).name }}
- name: Upload release assets
uses: AButler/[email protected]
with:
# e.g. dist/plugin-name-1.0.0.zip
files: "dist/${{ fromJson(needs.details.outputs.result).name }}-${{ fromJson(needs.details.outputs.result).version }}.zip"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy to WordPress.org
id: deploy
uses: 10up/action-wordpress-plugin-deploy@stable
with:
dry-run: true
env:
SLUG: ${{ fromJson(needs.details.outputs.result).name }}
VERSION: ${{ fromJson(needs.details.outputs.result).version }}
BUILD_DIR: "dist/${{ fromJson(needs.details.outputs.result).name }}"
ASSETS_DIR: "${{ fromJson(needs.details.outputs.result).path }}/.wordpress-org"
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}test
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}test

- name: Copy README.md to dist
run: |
cp ${{ fromJson(needs.details.outputs.result).path }}/README.md dist/${{ fromJson(needs.details.outputs.result).name }}/README.md
- name: Deploy to repo
uses: manzoorwanijk/action-deploy-to-repo@v3
with:
src_dir: dist/${{ fromJson(needs.details.outputs.result).name }}
target_repo: ${{ github.repository_owner }}/${{ fromJson(needs.details.outputs.result).name }}
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

details:
name: Get details
runs-on: ubuntu-latest
outputs:
result: ${{ steps.details.outputs.result }}
steps:
- name: Get release 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) {
throw new Error('Invalid tag name: ${{ github.event.release.tag_name }}');
}
const { name, version } = result.groups;
const plugins = [
'wptelegram',
'wptelegram-comments',
'wptelegram-login',
'wptelegram-widget',
];
const themes = [];
const toDeploy = [...plugins, ...themes];
const belongsTo = plugins.includes(name)
? 'plugins'
: themes.includes(name)
? 'themes'
: '';
const path = [belongsTo, name].filter(Boolean).join('/');
const shouldDeploy = toDeploy.includes(name);
return { name, version, path, shouldDeploy };
- name: Print details
run: |
echo "Package details: ${{ steps.details.outputs.result }}"
76 changes: 11 additions & 65 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,15 @@ jobs:
matrix:
php: ["7.4", "8.0", "8.1", "8.2", "8.3"]
steps:
- name: Check out code
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: lts/*

- uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: |
${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/package.json', '**/pnpm-hashed.lock') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup Environment
uses: ./actions/setup
with:
lockfile: pnpm-hashed.lock
php-version: ${{ matrix.php }}
tools: phpcs
enable-wireit-cache: true

- name: Check syntax errors
# For plugins, we need to check production dependencies as well
Expand All @@ -59,7 +31,7 @@ jobs:
pnpm -r --parallel --filter "./plugins/**" exec composer install --no-dev
find ./plugins/*/src ./packages/php/*/src ! -path "*/vendor/*" ! -path "*/node_modules/*" -type f -name '*.php' -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" )
- name: Setup
- name: Setup PHP
run: "pnpm run setup:php"

- name: Lint
Expand All @@ -75,40 +47,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Check out code
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: lts/*

- uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v3
name: Setup pnpm cache
- name: Setup Environment
uses: ./actions/setup
with:
path: |
${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/package.json', '**/pnpm-hashed.lock') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Wireit cache
uses: google/wireit@setup-github-actions-caching/v1

- name: Install dependencies
run: pnpm install
lockfile: pnpm-hashed.lock
enable-wireit-cache: true

- name: Lint
run: "pnpm lint:js"
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Prepare or publish release

on:
push:
branches:
- main

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

jobs:
release:
name: Prepare or publish release
if: github.repository == 'irshadahmad21/wp-plugins-dev-test'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./actions/setup
with:
lockfile: pnpm-hashed.lock
enable-wireit-cache: true

- name: Create Release Pull Request or Publish
uses: changesets/action@v1
id: changesets
with:
publish: pnpm release
version: pnpm prep-version
title: Prepare for next release
commit: Prepare for next release
env:
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vendor/
!/.changeset/
!/.github/
!/.vscode/
!/actions/
!/packages/
!/plugins/
!/tools/
Expand Down Expand Up @@ -42,4 +43,5 @@ build/
dist/
.env
temp/
js-translations.pot
js-translations.pot
changeset-status.json
87 changes: 87 additions & 0 deletions actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: "Setup Node, pnpm, PHP, WP CLI and install dependencies"
description: "This action checks out the commit, sets up Node, pnpm, PHP, WP CLI and installs dependencies."
author: "wpsocio"
inputs:
cache-key:
required: false
description: "Cache busting key. If this changes, the cache will be busted."
default: "1"

node-version:
required: false
description: "The version of Node to use."
default: "lts/*"

php-version:
required: false
description: "The version of PHP to use."
default: "8"

pnpm-version:
required: false
description: "The version of pnpm to use."
default: "latest"

lockfile:
required: false
description: "The lockfile to use."
default: "pnpm-lock.yaml"

enable-wireit-cache:
required: false
description: "Enable Wireit cache."
default: "false"

runs:
using: "composite"
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}

- uses: pnpm/action-setup@v2
with:
version: ${{ inputs.pnpm-version }}
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: |
${{ env.STORE_PATH }}
key: ${{ runner.os }}-modules-${{ inputs.cache-key }}-${{ hashFiles( inputs.lockfile ) }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Wireit cache
if: ${{ inputs.enable-wireit-cache == 'true' }}
uses: google/wireit@setup-github-actions-caching/v1

- name: Install dependencies
shell: bash
run: pnpm install

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
tools: phpcs

- name: Install gettext
shell: bash
run: sudo apt install gettext

- name: Setup WP-CLI
shell: bash
run: |
curl -O 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
# Check WP-CLI
wp --info
Loading

0 comments on commit 7b30e81

Please sign in to comment.