diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 18648e3..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,30 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: "circleci/node:latest" - steps: - - checkout - - run: - name: Install nvm and use the node version defined in .nvmrc - command: | - # https://support.circleci.com/hc/en-us/articles/360051656632-Swap-node-version-on-CircleCI-convenience-image - set +e - wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" - nvm install - nvm use - # https://stackoverflow.com/a/61823737/3772847 - NODE_DIR=$(dirname $(which node)) - echo "export PATH=$NODE_DIR:\$PATH" >> $BASH_ENV - - run: - name: Check node version (should match the version set in project's .nvmrc file) - command: node --version - - run: - name: install - command: npm install --legacy-peer-deps - - run: - name: release - command: npm run semantic-release || true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..82063d1 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/.github/workflows/reusable-build-distributable.yml b/.github/workflows/reusable-build-distributable.yml new file mode 100644 index 0000000..06308e3 --- /dev/null +++ b/.github/workflows/reusable-build-distributable.yml @@ -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 diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml new file mode 100644 index 0000000..97267a2 --- /dev/null +++ b/.github/workflows/reusable-build.yml @@ -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 diff --git a/.github/workflows/reusable-check-typescript.yml b/.github/workflows/reusable-check-typescript.yml new file mode 100644 index 0000000..b754310 --- /dev/null +++ b/.github/workflows/reusable-check-typescript.yml @@ -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 diff --git a/.github/workflows/reusable-generate-docs.yml b/.github/workflows/reusable-generate-docs.yml new file mode 100644 index 0000000..9ceb1b6 --- /dev/null +++ b/.github/workflows/reusable-generate-docs.yml @@ -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 diff --git a/.github/workflows/reusable-i18n.yml b/.github/workflows/reusable-i18n.yml new file mode 100644 index 0000000..bc92842 --- /dev/null +++ b/.github/workflows/reusable-i18n.yml @@ -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 diff --git a/.github/workflows/reusable-lint-js-scss.yml b/.github/workflows/reusable-lint-js-scss.yml new file mode 100644 index 0000000..95f016d --- /dev/null +++ b/.github/workflows/reusable-lint-js-scss.yml @@ -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 diff --git a/.github/workflows/reusable-lint-php.yml b/.github/workflows/reusable-lint-php.yml new file mode 100644 index 0000000..60135c2 --- /dev/null +++ b/.github/workflows/reusable-lint-php.yml @@ -0,0 +1,30 @@ +name: Lint PHP + +on: + workflow_call: + inputs: + php-version: + description: 'PHP version to use' + required: false + type: string + default: '8.3' + +jobs: + lint-php: + name: Lint PHP files + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php-version }} + tools: composer + + - name: Install Composer dependencies + run: composer install + + - name: Lint PHP files + run: ./vendor/bin/phpcs diff --git a/.github/workflows/reusable-post-release.yml b/.github/workflows/reusable-post-release.yml new file mode 100644 index 0000000..611f491 --- /dev/null +++ b/.github/workflows/reusable-post-release.yml @@ -0,0 +1,33 @@ +name: Post Release + +on: + workflow_call: + secrets: + SLACK_CHANNEL_ID: + required: false + SLACK_AUTH_TOKEN: + required: false + +jobs: + post-release: + name: Perform post-release tasks + 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: Perform post-release chores + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }} + SLACK_AUTH_TOKEN: ${{ secrets.SLACK_AUTH_TOKEN }} + run: ./node_modules/newspack-scripts/post-release.sh diff --git a/.github/workflows/reusable-release.yml b/.github/workflows/reusable-release.yml new file mode 100644 index 0000000..f35f8b6 --- /dev/null +++ b/.github/workflows/reusable-release.yml @@ -0,0 +1,46 @@ +name: Release + +on: + workflow_call: + secrets: + NPM_TOKEN: + required: false + +jobs: + release: + name: Release new version + 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 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: Release new version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm run release diff --git a/.github/workflows/reusable-test-js.yml b/.github/workflows/reusable-test-js.yml new file mode 100644 index 0000000..e5dd261 --- /dev/null +++ b/.github/workflows/reusable-test-js.yml @@ -0,0 +1,27 @@ +name: Test JS + +on: + workflow_call: + +jobs: + test-js: + name: Run JS tests + 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 JS Tests + run: npm run test diff --git a/.github/workflows/reusable-test-php.yml b/.github/workflows/reusable-test-php.yml new file mode 100644 index 0000000..d13be96 --- /dev/null +++ b/.github/workflows/reusable-test-php.yml @@ -0,0 +1,73 @@ +name: Test PHP + +on: + workflow_call: + inputs: + php-version: + description: 'PHP version to use' + required: false + type: string + default: '8.3' + wp-version: + description: 'WordPress version to test against' + required: false + type: string + default: 'latest' + secrets: + CODECOV_TOKEN: + required: false + +jobs: + test-php: + name: Run PHP tests + runs-on: ubuntu-latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + env: + WP_TESTS_DIR: /tmp/wordpress-tests-lib + WP_CORE_DIR: /tmp/wordpress/ + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php-version }} + tools: composer + extensions: mysqli + coverage: pcov + + - name: Install system dependencies + run: sudo apt-get update && sudo apt-get install -y subversion + + - name: Install Composer dependencies + run: composer update + + - name: Setup WordPress test environment + run: | + rm -rf $WP_TESTS_DIR $WP_CORE_DIR + bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 ${{ inputs.wp-version }} + + - name: Run tests with coverage + run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover coverage.xml + + - name: Upload coverage to Codecov + if: ${{ env.CODECOV_TOKEN != '' }} + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage.xml + fail_ci_if_error: false + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/post-release.sh b/post-release.sh index 7bac57a..b8a1c19 100755 --- a/post-release.sh +++ b/post-release.sh @@ -23,13 +23,13 @@ if [[ $(echo $SECOND_TO_LAST_COMMIT_MSG | grep '^Merge .*alpha') ]]; then # we don't care about any alpha changes. git reset --hard release -- # Force-push the alpha branch. - git push "https://$GITHUB_TOKEN@github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git" --force + git push "https://$GITHUB_TOKEN@github.com/${GITHUB_REPOSITORY}.git" --force else echo '[newspack-scripts] Release was created from a different branch than the alpha branch (e.g. a hotfix branch).' echo '[newspack-scripts] Alpha branch will now be updated with the lastest changes from release.' git merge --no-ff release -m "chore(release): merge in release $LATEST_VERSION_TAG" if [[ $? == 0 ]]; then - git push "https://$GITHUB_TOKEN@github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git" + git push "https://$GITHUB_TOKEN@github.com/${GITHUB_REPOSITORY}.git" else git merge --abort echo '[newspack-scripts] Post-release merge to alpha failed.' @@ -55,7 +55,7 @@ git checkout trunk git merge --no-ff release -m "chore(release): merge in release $LATEST_VERSION_TAG" if [[ $? == 0 ]]; then echo '[newspack-scripts] Pushing updated trunk to origin.' - git push "https://$GITHUB_TOKEN@github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git" + git push "https://$GITHUB_TOKEN@github.com/${GITHUB_REPOSITORY}.git" else git merge --abort echo '[newspack-scripts] Post-release merge to trunk failed.' diff --git a/scripts/release.js b/scripts/release.js index 40c3974..2f26744 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -10,24 +10,32 @@ const { files, ...otherArgs } = require( 'yargs/yargs' )( const filesList = files.split( ',' ); -utils.log( `Releasing ${ process.env.CIRCLE_PROJECT_REPONAME }…` ); +// Get repository name from GitHub Actions environment variable (format: owner/repo). +const repoName = process.env.GITHUB_REPOSITORY?.split( '/' )[ 1 ] || 'unknown'; + +utils.log( `Releasing ${ repoName }…` ); const getConfig = ({ gitBranchName }) => { const branchType = gitBranchName.split("/")[0]; const githubConfig = { assets: [ { - path: `./release/${process.env.CIRCLE_PROJECT_REPONAME}.zip`, - label: `${process.env.CIRCLE_PROJECT_REPONAME}.zip`, + path: `./release/${ repoName }.zip`, + label: `${ repoName }.zip`, }, ], + // Custom label template that caps at 50 chars (GitHub's limit). + releasedLabels: [ + '<%= ("released" + (nextRelease.channel ? " on @" + nextRelease.channel : "")).substring(0, 50) %>', + ], }; // Only post GH PR comments for alpha, hotfix/*, and release branches. - if ( ! ["alpha", "hotfix", "release"].includes(branchType) ) { - githubConfig.successComment = false; - githubConfig.failComment = false; - } + // if ( ! ["alpha", "hotfix", "release"].includes(branchType) ) { + // Temporarily disable comments for all branches to prevent spam. + githubConfig.successComment = false; + githubConfig.failComment = false; + // } // Only publish alpha and release branches to NPM. const shouldPublishOnNPM = Boolean( process.env.NPM_TOKEN ) && ["alpha", "release"].includes(branchType); diff --git a/src/@orb.yml b/src/@orb.yml deleted file mode 100755 index 5270831..0000000 --- a/src/@orb.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: 2.1 - -description: > - Newspack shared CI config. - -display: - home_url: "https://newspack.com" - source_url: "https://www.github.com/Automattic/newspack-scripts" diff --git a/src/commands/checkout_with_workspace.yml b/src/commands/checkout_with_workspace.yml deleted file mode 100755 index ad3ec5a..0000000 --- a/src/commands/checkout_with_workspace.yml +++ /dev/null @@ -1,6 +0,0 @@ -description: > - Chechout code and attach workspace. -steps: - - checkout - - attach_workspace: - at: ~/ diff --git a/src/commands/set_node_version.yml b/src/commands/set_node_version.yml deleted file mode 100755 index 258ede4..0000000 --- a/src/commands/set_node_version.yml +++ /dev/null @@ -1,20 +0,0 @@ -description: > - Set node version to the one defined in the .nvmrc file. -steps: - - run: - name: Install nvm and use the node version defined in .nvmrc - command: | - # https://support.circleci.com/hc/en-us/articles/360051656632-Swap-node-version-on-CircleCI-convenience-image - set +e - wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" - nvm install - nvm use - # https://stackoverflow.com/a/61823737/3772847 - NODE_DIR=$(dirname $(which node)) - echo "export PATH=$NODE_DIR:\$PATH" >> $BASH_ENV - - run: - name: Check node version (should match the version set in project's .nvmrc file) - command: node --version diff --git a/src/executors/default.yml b/src/executors/default.yml deleted file mode 100755 index b9c2e06..0000000 --- a/src/executors/default.yml +++ /dev/null @@ -1,8 +0,0 @@ -description: PHP executor -docker: - - image: "cimg/php:<>" -parameters: - tag: - default: 8.3-node - description: PHP image version - type: string diff --git a/src/executors/php-81.yml b/src/executors/php-81.yml deleted file mode 100755 index c7e0dfc..0000000 --- a/src/executors/php-81.yml +++ /dev/null @@ -1,8 +0,0 @@ -description: PHP executor -docker: - - image: "cimg/php:<>" -parameters: - tag: - default: 8.1-node - description: PHP image version - type: string diff --git a/src/jobs/build-distributable.yml b/src/jobs/build-distributable.yml deleted file mode 100644 index 79ceb98..0000000 --- a/src/jobs/build-distributable.yml +++ /dev/null @@ -1,25 +0,0 @@ -description: > - Build the distributable files, so they are available as CI artifacts. - -executor: default - -parameters: - archive-name: - type: string - default: "" - description: "Name of the ZIP archive distributable." - -steps: - - checkout_with_workspace - - set_node_version - - run: - name: Install rsync - command: sudo apt-get update && sudo apt-get install rsync - - run: - name: Install PHP packages - command: composer install --no-dev --no-scripts - - run: - name: Build plugin files - command: npm run build && npm run release:archive - - store_artifacts: - path: release/<>.zip diff --git a/src/jobs/build.yml b/src/jobs/build.yml deleted file mode 100755 index dce2c58..0000000 --- a/src/jobs/build.yml +++ /dev/null @@ -1,28 +0,0 @@ -description: > - Install node dependencies. - -executor: default - -steps: - - checkout_with_workspace - - set_node_version - - restore_cache: - key: v1-npm-{{ checksum "package.json" }}-{{checksum "package-lock.json" }}-{{ checksum ".nvmrc" }} - # https://medium.com/@mdsky1986/caching-node-dependencies-when-using-npm-ci-89fe3f46404a - - run: - name: Install node dependencies - # --legacy-peer-deps flag should be removed once https://github.com/Automattic/newspack-plugin/issues/1218 is resolved - command: | - if test -d "node_modules"; then - echo "package.json and package-lock.json unchanged. Using cache." - else - npm ci --legacy-peer-deps --loglevel warn --yes - fi - - save_cache: - key: v1-npm-{{ checksum "package.json" }}-{{checksum "package-lock.json" }}-{{ checksum ".nvmrc" }} - paths: - - node_modules - - persist_to_workspace: - root: ~/ - paths: - - project diff --git a/src/jobs/check-typescript.yml b/src/jobs/check-typescript.yml deleted file mode 100644 index 3af092a..0000000 --- a/src/jobs/check-typescript.yml +++ /dev/null @@ -1,11 +0,0 @@ -description: > - Validate TypeScript. - -executor: default - -steps: - - checkout_with_workspace - - set_node_version - - run: - name: Validate TypeScript - command: npm run typescript:check diff --git a/src/jobs/generate-docs.yml b/src/jobs/generate-docs.yml deleted file mode 100644 index 6a878d8..0000000 --- a/src/jobs/generate-docs.yml +++ /dev/null @@ -1,30 +0,0 @@ -description: > - Generate documentation. This will create a new branch called docs and push the HTML documentation to it, as /docs directory. - To make this work with GH pages, visit /settings/pages, set branch to "docs", and folder to "/docs". - -executor: php-81 - -steps: - - checkout - - run: - name: Install dependencies - command: | - sudo apt-get update && sudo apt-get install -y graphviz plantuml - - run: - name: Download PHPDocumentor - command: | - curl -L -o ./phpdocumentor https://phpdoc.org/phpDocumentor.phar - chmod +x ./phpdocumentor - - run: - name: Generate documentation - command: | - ./phpdocumentor run -d . -t ./docs - - run: - name: Switch to docs branch, commit, and push - command: | - git config user.name "${GIT_COMMITTER_NAME}" - git config user.email "${GITHUB_COMMITER_EMAIL}" - git checkout -b docs - git add -f docs - git commit -m "Update the docs" - git push "https://${GITHUB_TOKEN}@github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}.git" --force diff --git a/src/jobs/i18n.yml b/src/jobs/i18n.yml deleted file mode 100644 index 684bff7..0000000 --- a/src/jobs/i18n.yml +++ /dev/null @@ -1,91 +0,0 @@ -description: > - Create translation files. - -executor: default - -steps: - - checkout_with_workspace - - run: - name: Check if commit author is bot - command: | - COMMIT_AUTHOR=$(git log -1 --pretty=format:'%ae') - if [ "$COMMIT_AUTHOR" = "$GITHUB_COMMITER_EMAIL" ]; then - echo "Commit was made by bot ($(git rev-parse --short HEAD)), skipping translation update" - circleci step halt - fi - - run: - name: Install WP CLI - command: | - 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 - - run: - name: Build plugin files, so dist dir is available - command: | - npm run build || true - - run: - name: Create POT translation files - command: | - # Theme is excluded, more in https://github.com/Automattic/newspack-theme/pull/2458 - if [ "$CIRCLE_PROJECT_REPONAME" = "newspack-theme" ]; then - cd ./newspack-theme - wp i18n make-pot . languages/${CIRCLE_PROJECT_REPONAME}.pot --exclude='src' --domain=${CIRCLE_PROJECT_REPONAME} - cd - - else - wp i18n make-pot . languages/${CIRCLE_PROJECT_REPONAME}.pot --domain=${CIRCLE_PROJECT_REPONAME} - fi - - run: - name: Create JSON translation files - command: | - if [ "$CIRCLE_PROJECT_REPONAME" = "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 "${CIRCLE_PROJECT_REPONAME}-en_US.po" ]; then - echo "Creating ${CIRCLE_PROJECT_REPONAME}-en_US.po from POT file" - wp i18n update-po ${CIRCLE_PROJECT_REPONAME}.pot . - else - echo "${CIRCLE_PROJECT_REPONAME}-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 $CIRCLE_PROJECT_REPONAME.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 - - run: - name: Commit translation files - command: | - if [ "$CIRCLE_PROJECT_REPONAME" = "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 "$GITHUB_COMMITER_EMAIL" - git config user.name "$GIT_COMMITTER_NAME" - git remote set-url origin https://$GITHUB_TOKEN@github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git - git add languages/ - git commit -m "chore: update translation files [skip ci]" - git push origin $CIRCLE_BRANCH - fi diff --git a/src/jobs/lint-js-scss.yml b/src/jobs/lint-js-scss.yml deleted file mode 100644 index 86873d2..0000000 --- a/src/jobs/lint-js-scss.yml +++ /dev/null @@ -1,11 +0,0 @@ -description: > - Lint the JS & SCSS (temporarily skipped) files. - -executor: default - -steps: - - checkout_with_workspace - - set_node_version - - run: - name: Run Linter - command: npm run lint:js # Temporarily skip linting SCSS due to stylelint config updates. Remove :js when ready to re-enable linting of SCSS. diff --git a/src/jobs/lint-php.yml b/src/jobs/lint-php.yml deleted file mode 100644 index eae5746..0000000 --- a/src/jobs/lint-php.yml +++ /dev/null @@ -1,12 +0,0 @@ -description: > - Lint PHP files. - -executor: default - -steps: - - checkout - - run: - name: Lint Files - command: | - composer install - ./vendor/bin/phpcs diff --git a/src/jobs/post-release.yml b/src/jobs/post-release.yml deleted file mode 100644 index 418d190..0000000 --- a/src/jobs/post-release.yml +++ /dev/null @@ -1,10 +0,0 @@ -description: > - Perform post-release tasks. - -executor: default - -steps: - - checkout_with_workspace - - run: - name: Perform post-release chores - command: ./node_modules/newspack-scripts/post-release.sh diff --git a/src/jobs/release.yml b/src/jobs/release.yml deleted file mode 100644 index 09f977f..0000000 --- a/src/jobs/release.yml +++ /dev/null @@ -1,21 +0,0 @@ -description: > - Release new version. - -executor: default - -steps: - - checkout_with_workspace - - set_node_version - - run: - name: Install rsync - command: sudo apt-get update && sudo apt-get install rsync - - run: - name: Install PHP packages - command: composer install --no-dev --no-scripts - - run: - name: Release new version - command: npm run release - - persist_to_workspace: - root: ~/ - paths: - - project diff --git a/src/jobs/test-js.yml b/src/jobs/test-js.yml deleted file mode 100644 index 5c5ddae..0000000 --- a/src/jobs/test-js.yml +++ /dev/null @@ -1,11 +0,0 @@ -description: > - Run JS tests. - -executor: default - -steps: - - checkout_with_workspace - - set_node_version - - run: - name: Run JS Tests - command: npm run test diff --git a/src/jobs/test-php.yml b/src/jobs/test-php.yml deleted file mode 100644 index c27feff..0000000 --- a/src/jobs/test-php.yml +++ /dev/null @@ -1,49 +0,0 @@ -description: > - Run PHP tests. - -docker: - - image: cimg/php:8.3 - - image: circleci/mysql:5.6.50 - -environment: - - WP_TESTS_DIR: "/tmp/wordpress-tests-lib" - - WP_CORE_DIR: "/tmp/wordpress/" -steps: - - checkout - - run: - name: Setup Environment Variables - command: | - echo "export PATH=$HOME/.composer/vendor/bin:$PATH" >> $BASH_ENV - source /home/circleci/.bashrc - - run: - name: Install Dependencies - command: | - sudo apt-get update && sudo apt-get install -y subversion default-mysql-client - - run: - name: Run Tests with Coverage - command: | - composer update - rm -rf $WP_TESTS_DIR $WP_CORE_DIR - bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest - # https://circleci.com/docs/code-coverage/#php - XDEBUG_MODE=coverage phpdbg -qrr vendor/bin/phpunit --coverage-clover coverage.xml - - run: - name: Upload Test Results to Codecov - command: | - if [[ -n $CODECOV_TOKEN ]]; then - # download Codecov CLI - curl -Os https://cli.codecov.io/latest/linux/codecov - - # integrity check - curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import # One-time step - curl -Os https://cli.codecov.io/latest/linux/codecov - curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM - curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM.sig - gpgv codecov.SHA256SUM.sig codecov.SHA256SUM - - shasum -a 256 -c codecov.SHA256SUM - sudo chmod +x codecov - ./codecov upload-process -t $CODECOV_TOKEN - else - echo "CODECOV_TOKEN is not set. Skipping upload to Codecov." - fi