diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index a67112aac..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,122 +0,0 @@ -version: 2.1 - -orbs: - newspack: newspack/newspack@1.5.8 - -commands: - checkout_code: - steps: - - checkout - - attach_workspace: - at: ~/ - -jobs: - build: - docker: - - image: cimg/node:lts - steps: - - checkout_code - - run: - name: Install dependencies - command: npm ci - - persist_to_workspace: - root: ~/ - paths: - - project - - # Build distributable ZIP files. - build_distributables: - docker: - - image: cimg/node:lts - steps: - - checkout_code - - run: - name: Build theme ZIPs - command: npm run build && npm run release:archive - - store_artifacts: - path: release/newspack-joseph.zip - - store_artifacts: - path: release/newspack-katharine.zip - - store_artifacts: - path: release/newspack-nelson.zip - - store_artifacts: - path: release/newspack-sacha.zip - - store_artifacts: - path: release/newspack-scott.zip - - store_artifacts: - path: release/newspack-theme.zip - - # Linting - lint: - docker: - - image: cimg/node:lts - steps: - - checkout_code - - run: - name: Run Linter - command: npm run lint - - # Release job - release: - docker: - - image: cimg/node:lts - steps: - - checkout_code - - run: - name: Release new version - command: npm run release - - persist_to_workspace: - root: ~/ - paths: - - project - - # Reset alpha branch after a release and publish child themes' releases - post_release: - docker: - - image: cimg/node:lts - steps: - - checkout_code - - run: - name: Publish child themes' releases - command: node scripts/create-child-releases.js --run - - run: - name: Perform post-release chores - command: ./node_modules/newspack-scripts/post-release.sh - -workflows: - version: 2 - all: - jobs: - - build - - newspack/i18n: - requires: - - build - filters: - branches: - only: - - trunk - - lint: - requires: - - build - - release: - requires: - - build - filters: - branches: - only: - - release - - alpha - - /^hotfix\/.*/ - - /^epic\/.*/ - - build_distributables: - requires: - - build - # Running this after release ensure the version number in files will be correct. - - release - - post_release: - requires: - - release - filters: - branches: - only: - - release diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 000000000..10c7a3f6d --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,23 @@ +name: Build and Test + +on: + pull_request: + push: + branches: + - trunk + - release + - alpha + - 'hotfix/**' + - 'epic/**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + uses: Automattic/newspack-scripts/.github/workflows/reusable-build.yml + + lint-js-scss: + needs: build + uses: Automattic/newspack-scripts/.github/workflows/reusable-lint-js-scss.yml diff --git a/.github/workflows/build-distributable.yml b/.github/workflows/build-distributable.yml new file mode 100644 index 000000000..fc2bcd2d8 --- /dev/null +++ b/.github/workflows/build-distributable.yml @@ -0,0 +1,64 @@ +name: Build distributable + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-distributable: + name: Build theme ZIPs + 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: Install dependencies + run: npm ci --legacy-peer-deps + + - name: Build and create archives + run: npm run build && npm run release:archive + + - name: Upload newspack-theme + uses: actions/upload-artifact@v4 + with: + name: newspack-theme + path: release/newspack-theme.zip + + - name: Upload newspack-joseph + uses: actions/upload-artifact@v4 + with: + name: newspack-joseph + path: release/newspack-joseph.zip + + - name: Upload newspack-katharine + uses: actions/upload-artifact@v4 + with: + name: newspack-katharine + path: release/newspack-katharine.zip + + - name: Upload newspack-nelson + uses: actions/upload-artifact@v4 + with: + name: newspack-nelson + path: release/newspack-nelson.zip + + - name: Upload newspack-sacha + uses: actions/upload-artifact@v4 + with: + name: newspack-sacha + path: release/newspack-sacha.zip + + - name: Upload newspack-scott + uses: actions/upload-artifact@v4 + with: + name: newspack-scott + path: release/newspack-scott.zip diff --git a/.github/workflows/i18n.yml b/.github/workflows/i18n.yml new file mode 100644 index 000000000..b1c45ab60 --- /dev/null +++ b/.github/workflows/i18n.yml @@ -0,0 +1,14 @@ +name: Internationalization + +on: + push: + branches: + - trunk + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + i18n: + uses: Automattic/newspack-scripts/.github/workflows/reusable-i18n.yml@trunk diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 000000000..151129ad4 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,19 @@ +name: PHP + +on: + pull_request: + push: + branches: + - trunk + - release + - alpha + - 'hotfix/**' + - 'epic/**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint-php: + uses: Automattic/newspack-scripts/.github/workflows/reusable-lint-php.yml@trunk diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..c3e7f0c39 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: Release + +on: + push: + branches: + - release + - alpha + - 'hotfix/**' + - 'epic/**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + uses: Automattic/newspack-scripts/.github/workflows/reusable-build.yml@trunk + + release: + needs: build + uses: Automattic/newspack-scripts/.github/workflows/reusable-release.yml@trunk + secrets: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + post-release: + if: github.ref == 'refs/heads/release' + needs: release + uses: Automattic/newspack-scripts/.github/workflows/reusable-post-release.yml@trunk diff --git a/.github/workflows/reusable-sync-release.yml b/.github/workflows/reusable-sync-release.yml new file mode 100644 index 000000000..6eee1c886 --- /dev/null +++ b/.github/workflows/reusable-sync-release.yml @@ -0,0 +1,64 @@ +name: Sync Release + +on: + workflow_call: + inputs: + theme: + description: 'Theme name (e.g., newspack-joseph)' + required: true + type: string + +jobs: + sync-release: + runs-on: ubuntu-latest + steps: + - name: Sync releases from newspack-theme + env: + GH_TOKEN: ${{ github.token }} + run: | + # Get last 5 releases (including pre-releases) + RELEASES=$(gh release list --repo Automattic/newspack-theme --limit 5 --json tagName,name,isPrerelease) + + # Process each release (oldest first to maintain chronological order) + echo "$RELEASES" | jq -c 'reverse | .[]' | while read -r RELEASE; do + TAG=$(echo "$RELEASE" | jq -r '.tagName') + NAME=$(echo "$RELEASE" | jq -r '.name') + IS_PRERELEASE=$(echo "$RELEASE" | jq -r '.isPrerelease') + + echo "Checking release: $TAG" + + # Check if release already exists + if gh release view "$TAG" --repo ${{ github.repository }} > /dev/null 2>&1; then + echo "Release $TAG already exists, skipping..." + continue + fi + + echo "Creating release: $TAG" + + # Fetch release body + BODY=$(gh release view "$TAG" --repo Automattic/newspack-theme --json body -q '.body') + + # Download theme ZIP + gh release download "$TAG" \ + --repo Automattic/newspack-theme \ + --pattern "${{ inputs.theme }}.zip" \ + --dir . + + # Create release + PRERELEASE_FLAG="" + if [ "$IS_PRERELEASE" = "true" ]; then + PRERELEASE_FLAG="--prerelease" + fi + + gh release create "$TAG" \ + --repo ${{ github.repository }} \ + --title "$NAME" \ + --notes "$BODY" \ + $PRERELEASE_FLAG \ + "${{ inputs.theme }}.zip" + + # Clean up ZIP for next iteration + rm -f "${{ inputs.theme }}.zip" + + echo "Release $TAG created successfully" + done diff --git a/.releaserc.js b/.releaserc.js index fda7d12f8..b896672a1 100644 --- a/.releaserc.js +++ b/.releaserc.js @@ -1,6 +1,11 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ - -const { THEMES } = require( './scripts/create-child-releases.js' ); +const THEMES = [ + 'newspack-theme', + 'newspack-joseph', + 'newspack-katharine', + 'newspack-nelson', + 'newspack-sacha', + 'newspack-scott', +]; module.exports = { branches: [ diff --git a/package-lock.json b/package-lock.json index cb353fdca..398004b52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22652,8 +22652,8 @@ }, "node_modules/newspack-scripts": { "version": "5.8.0", - "resolved": "https://registry.npmjs.org/newspack-scripts/-/newspack-scripts-5.8.0.tgz", - "integrity": "sha512-INOymPHxavzLFziqa9zcfB9KRfi9w+FOwq1cNj8IKnfBSlWrYMLsw43LMgAk7wrGtv6crvHEREweHhPGWMAtGQ==", + "resolved": "git+ssh://git@github.com/Automattic/newspack-scripts.git#1b654fae0446656ac8221ae7400a42bbd80b2140", + "integrity": "sha512-NzUACVvKJJLiYXtFIHmxZNzVsqmYJmW0HuzUpNa3Y/pJEUK1QfqWk+SCACTyDx7zXoNlIvjBTbNUD6R1zSF72w==", "dev": true, "license": "ISC", "dependencies": { diff --git a/scripts/create-child-releases.js b/scripts/create-child-releases.js deleted file mode 100644 index 0da4f82a8..000000000 --- a/scripts/create-child-releases.js +++ /dev/null @@ -1,98 +0,0 @@ -/* eslint-disable no-console, @typescript-eslint/no-var-requires */ - -const { basename, resolve } = require( 'path' ); -const { stat, readFile } = require( 'fs-extra' ); -const { Octokit } = require( '@octokit/rest' ); - -const THEMES = [ - 'newspack-theme', - 'newspack-joseph', - 'newspack-katharine', - 'newspack-nelson', - 'newspack-sacha', - 'newspack-scott', -]; - -/** - * Because all the themes are in a monorepo, some internal processes - * have a hard time automatically deploying the changes. For this reason - * the themes have individual repos just for the releases. - * These releases are automatically published using this script. - */ -const createExternalReleasesOfThemes = async () => { - const { version } = require( '../package.json' ); - - const TOKEN = process.env.GITHUB_TOKEN || process.env.GH_TOKEN; - - if ( ! TOKEN ) { - console.error( 'Missing github token.' ); - process.exit( 1 ); - } - - const octokit = new Octokit( { - auth: TOKEN, - request: { - fetch, - }, - } ); - - const RELEASES = THEMES.map( name => ( { - filePath: resolve( __dirname, `../release/${ name }.zip` ), - repoName: `${ name }-theme`, - } ) ); - - const owner = 'Automattic'; - - RELEASES.forEach( async ( { filePath, repoName } ) => { - console.log( `Crating a release for ${ owner }/${ repoName }…` ); - - const { - data: { upload_url: uploadUrl, id: releaseId }, - } = await octokit.repos.createRelease( { - owner, - repo: repoName, - tag_name: `v${ version }`, - name: `v${ version }`, - body: `Release v${ version }`, - // We'll create a draft release, append the assets to it, and then publish it. - // This is so that the assets are available when we get a Github release event. - draft: true, - } ); - - const file = await stat( resolve( filePath ) ); - const upload = { - url: uploadUrl, - data: await readFile( filePath ), - name: basename( filePath ), - headers: { - 'content-type': 'application/zip', - 'content-length': file.size, - }, - }; - - const { - data: { browser_download_url: downloadUrl }, - } = await octokit.repos.uploadReleaseAsset( upload ); - - console.log( `Published file ${ downloadUrl }` ); - const { - data: { html_url: url }, - } = await octokit.repos.updateRelease( { - owner, - repo: repoName, - release_id: releaseId, - draft: false, - } ); - - console.log( `Published GitHub release: ${ url }` ); - } ); -}; - -if ( process.argv.some( arg => arg.startsWith( '--run' ) ) ) { - createExternalReleasesOfThemes(); -} - -// Export for use of semantic-release config. -module.exports = { - THEMES, -};