Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .circleci/config.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release

on:
push:
branches:
- trunk
- alpha
- 'hotfix/**'
- 'epic/**'

jobs:
release:
name: Build and Release
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Verify Node version
run: node --version

- name: Install dependencies
run: npm install --legacy-peer-deps

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm run semantic-release
44 changes: 44 additions & 0 deletions .github/workflows/reusable-build-distributable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build Distributable

on:
workflow_call:
inputs:
archive-name:
description: 'Name of the ZIP archive distributable'
required: true
type: string

jobs:
build-distributable:
name: Build distributable files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Verify Node version
run: node --version

- name: Install dependencies
run: npm ci --legacy-peer-deps

- name: Install rsync
run: sudo apt-get update && sudo apt-get install -y rsync

- name: Install PHP packages
run: composer install --no-dev --no-scripts

- name: Build plugin files
run: npm run build && npm run release:archive

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.archive-name }}
path: release/${{ inputs.archive-name }}.zip
24 changes: 24 additions & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build

on:
workflow_call:

jobs:
build:
name: Install node dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Verify Node version
run: node --version

- name: Install dependencies
run: npm ci --legacy-peer-deps
27 changes: 27 additions & 0 deletions .github/workflows/reusable-check-typescript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Check TypeScript

on:
workflow_call:

jobs:
check-typescript:
name: Validate TypeScript
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Verify Node version
run: node --version

- name: Install dependencies
run: npm ci --legacy-peer-deps

- name: Validate TypeScript
run: npm run typescript:check
39 changes: 39 additions & 0 deletions .github/workflows/reusable-generate-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Generate Docs

on:
workflow_call:
secrets:
GITHUB_TOKEN:
required: true

jobs:
generate-docs:
name: Generate documentation
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y graphviz plantuml

- name: Download PHPDocumentor
run: |
curl -L -o ./phpdocumentor https://phpdoc.org/phpDocumentor.phar
chmod +x ./phpdocumentor

- name: Generate documentation
run: ./phpdocumentor run -d . -t ./docs

- name: Switch to docs branch, commit, and push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_COMMITTER_NAME: ${{ vars.GIT_COMMITTER_NAME || 'github-actions[bot]' }}
GIT_COMMITTER_EMAIL: ${{ vars.GIT_COMMITTER_EMAIL || 'github-actions[bot]@users.noreply.github.com' }}
run: |
git config user.name "$GIT_COMMITTER_NAME"
git config user.email "$GIT_COMMITTER_EMAIL"
git checkout -b docs
git add -f docs
git commit -m "Update the docs"
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" docs --force
130 changes: 130 additions & 0 deletions .github/workflows/reusable-i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: i18n

on:
workflow_call:

jobs:
i18n:
name: Create translation files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Check if commit author is bot
id: check-bot
env:
GIT_COMMITTER_EMAIL: ${{ vars.GIT_COMMITTER_EMAIL || 'github-actions[bot]@users.noreply.github.com' }}
run: |
COMMIT_AUTHOR=$(git log -1 --pretty=format:'%ae')
if [ "$COMMIT_AUTHOR" = "$GIT_COMMITTER_EMAIL" ]; then
echo "Commit was made by bot ($(git rev-parse --short HEAD)), skipping translation update"
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi

- name: Install dependencies
if: steps.check-bot.outputs.skip != 'true'
run: npm ci --legacy-peer-deps

- name: Configure PHP for deep nesting
if: steps.check-bot.outputs.skip != 'true'
run: |
# Increase xdebug max_nesting_level to handle deeply nested JS files
echo "xdebug.max_nesting_level=512" | sudo tee -a $(php -i | grep "Scan this dir for additional .ini files" | cut -d' ' -f9)/99-custom.ini

- name: Install WP CLI
if: steps.check-bot.outputs.skip != 'true'
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

- name: Build plugin files
if: steps.check-bot.outputs.skip != 'true'
run: npm run build || true

- name: Create POT translation files
if: steps.check-bot.outputs.skip != 'true'
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
# Theme is excluded, more in https://github.com/Automattic/newspack-theme/pull/2458
if [ "$REPO_NAME" = "newspack-theme" ]; then
cd ./newspack-theme
wp i18n make-pot . languages/${REPO_NAME}.pot --exclude='src' --domain=${REPO_NAME}
cd -
else
wp i18n make-pot . languages/${REPO_NAME}.pot --exclude='src' --domain=${REPO_NAME}
fi

- name: Create JSON translation files
if: steps.check-bot.outputs.skip != 'true'
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
if [ "$REPO_NAME" = "newspack-theme" ]; then
cd ./newspack-theme
fi

sudo apt-get update && sudo apt-get install -y gettext

cd languages

# Create PO files from POT if they don't exist
if [ ! -f "${REPO_NAME}-en_US.po" ]; then
echo "Creating ${REPO_NAME}-en_US.po from POT file"
wp i18n update-po ${REPO_NAME}.pot .
else
echo "${REPO_NAME}-en_US.po file already exists, skipping creation"
fi

for po in *.po; do
if [ -f "$po" ]; then
echo "Processing file $po …"
# Update translations according to the new POT file
msgmerge $po $REPO_NAME.pot -o $po.out
mv $po.out $po
msgfmt $po -o $(basename $po .po).mo
# no-purge since we need the JS translations for the next run
wp i18n make-json --no-purge $po .
fi
done

- name: Commit translation files
if: steps.check-bot.outputs.skip != 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_NAME: ${{ github.event.repository.name }}
GIT_COMMITTER_NAME: ${{ vars.GIT_COMMITTER_NAME || 'github-actions[bot]' }}
GIT_COMMITTER_EMAIL: ${{ vars.GIT_COMMITTER_EMAIL || 'github-actions[bot]@users.noreply.github.com' }}
run: |
if [ "$REPO_NAME" = "newspack-theme" ]; then
cd ./newspack-theme
fi
if [ -d "languages" ]; then
LINES_CHANGED=$(git diff --numstat languages/ | awk '{sum += $1 + $2} END {print sum}')
# If no existing files were changed, check for new files
if [ -z "$LINES_CHANGED" ] || [ "$LINES_CHANGED" -eq 0 ]; then
LINES_CHANGED=$(git ls-files --others --exclude-standard languages/ | xargs wc -l 2>/dev/null | tail -1 | awk '{print $1}')
fi
else
LINES_CHANGED=0
fi
LINES_CHANGED=${LINES_CHANGED:-0}
echo "Lines changed in languages/: $LINES_CHANGED"
if [ "$LINES_CHANGED" -gt 3 ]; then
git config user.email "$GIT_COMMITTER_EMAIL"
git config user.name "$GIT_COMMITTER_NAME"
git remote set-url origin https://x-access-token:$GITHUB_TOKEN@github.com/${{ github.repository }}.git
git add languages/
git commit -m "chore: update translation files [skip ci]"
git push origin ${{ github.ref_name }}
fi
28 changes: 28 additions & 0 deletions .github/workflows/reusable-lint-js-scss.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint JS & SCSS

on:
workflow_call:

jobs:
lint-js-scss:
name: Lint JS & SCSS files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Verify Node version
run: node --version

- name: Install dependencies
run: npm ci --legacy-peer-deps

- name: Run Linter
# Temporarily skip linting SCSS due to stylelint config updates. Remove :js when ready to re-enable linting of SCSS.
run: npm run lint:js
Loading