newspack-scripts 5.6.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,105 @@
1
- on: pull_request_review
2
- name: Label approved pull requests
1
+ on:
2
+ pull_request_review:
3
+ types: [submitted]
4
+ name: Label pull requests on review
3
5
  jobs:
4
6
  labelWhenApproved:
5
7
  name: Label when approved
6
8
  runs-on: ubuntu-latest
9
+ permissions:
10
+ contents: read
11
+ pull-requests: write
7
12
  steps:
8
- - name: Label when approved
9
- uses: abinoda/label-when-approved-action@master
10
- env:
11
- APPROVALS: '1'
12
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13
- ADD_LABEL: '[Status] Approved'
14
- # Needs to be URL-encoded, see https://github.com/abinoda/label-when-approved-action/pull/3#discussion_r321882620
15
- REMOVE_LABEL: '%5BStatus%5D%20Needs%20Review'
13
+ - name: Check if review is approved
14
+ id: check_approval
15
+ run: |
16
+ if [ "${{ github.event.review.state }}" = "approved" ]; then
17
+ echo "approved=true" >> $GITHUB_OUTPUT
18
+ else
19
+ echo "approved=false" >> $GITHUB_OUTPUT
20
+ fi
21
+
22
+ - name: Add approved label
23
+ if: steps.check_approval.outputs.approved == 'true'
24
+ uses: actions/github-script@v7
25
+ with:
26
+ script: |
27
+ const { owner, repo, number } = context.issue;
28
+
29
+ // Add the approved label
30
+ await github.rest.issues.addLabels({
31
+ owner,
32
+ repo,
33
+ issue_number: number,
34
+ labels: ['[Status] Approved']
35
+ });
36
+
37
+ // Remove the needs review label if it exists
38
+ try {
39
+ await github.rest.issues.removeLabel({
40
+ owner,
41
+ repo,
42
+ issue_number: number,
43
+ name: '[Status] Needs Review'
44
+ });
45
+ } catch (error) {
46
+ // Label might not exist, which is fine
47
+ console.log('Label "[Status] Needs Review" not found or already removed');
48
+ }
49
+
50
+ // Remove the needs changes or feedback label if it exists
51
+ try {
52
+ await github.rest.issues.removeLabel({
53
+ owner,
54
+ repo,
55
+ issue_number: number,
56
+ name: '[Status] Needs Changes or Feedback'
57
+ });
58
+ } catch (error) {
59
+ // Label might not exist, which is fine
60
+ console.log('Label "[Status] Needs Changes or Feedback" not found or already removed');
61
+ }
62
+
63
+ labelWhenChangesRequested:
64
+ name: Label when changes requested
65
+ runs-on: ubuntu-latest
66
+ permissions:
67
+ contents: read
68
+ pull-requests: write
69
+ steps:
70
+ - name: Check if review requests changes
71
+ id: check_changes_requested
72
+ run: |
73
+ if [ "${{ github.event.review.state }}" = "changes_requested" ]; then
74
+ echo "changes_requested=true" >> $GITHUB_OUTPUT
75
+ else
76
+ echo "changes_requested=false" >> $GITHUB_OUTPUT
77
+ fi
78
+
79
+ - name: Add changes requested label
80
+ if: steps.check_changes_requested.outputs.changes_requested == 'true'
81
+ uses: actions/github-script@v7
82
+ with:
83
+ script: |
84
+ const { owner, repo, number } = context.issue;
85
+
86
+ // Add the changes requested label
87
+ await github.rest.issues.addLabels({
88
+ owner,
89
+ repo,
90
+ issue_number: number,
91
+ labels: ['[Status] Needs Changes or Feedback']
92
+ });
93
+
94
+ // Remove the approved label if it exists
95
+ try {
96
+ await github.rest.issues.removeLabel({
97
+ owner,
98
+ repo,
99
+ issue_number: number,
100
+ name: '[Status] Approved'
101
+ });
102
+ } catch (error) {
103
+ // Label might not exist, which is fine
104
+ console.log('Label "[Status] Approved" not found or already removed');
105
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newspack-scripts",
3
- "version": "5.6.0",
3
+ "version": "5.7.0",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "newspack-scripts": "./bin/newspack-scripts.js"
@@ -54,7 +54,7 @@
54
54
  "postcss-focus-within": "^5.0.4",
55
55
  "postcss-scss": "^4.0.9",
56
56
  "prettier": "npm:wp-prettier@^3.0.3",
57
- "semantic-release": "^19.0.5",
57
+ "semantic-release": "^22.0.0",
58
58
  "semantic-release-version-bump": "^1.4.1",
59
59
  "stylelint": "^14.2.0",
60
60
  "typescript": "^5.4.5",
@@ -12,12 +12,6 @@ const filesList = files.split( ',' );
12
12
 
13
13
  utils.log( `Releasing ${ process.env.CIRCLE_PROJECT_REPONAME }…` );
14
14
 
15
- const shouldPublishOnNPM = Boolean( process.env.NPM_TOKEN );
16
-
17
- if ( shouldPublishOnNPM ) {
18
- utils.log( `Will publish on npm` );
19
- }
20
-
21
15
  const getConfig = ({ gitBranchName }) => {
22
16
  const branchType = gitBranchName.split("/")[0];
23
17
  const githubConfig = {
@@ -35,6 +29,12 @@ const getConfig = ({ gitBranchName }) => {
35
29
  githubConfig.failComment = false;
36
30
  }
37
31
 
32
+ // Only publish alpha and release branches to NPM.
33
+ const shouldPublishOnNPM = Boolean( process.env.NPM_TOKEN ) && ["alpha", "release"].includes(branchType);
34
+ if ( shouldPublishOnNPM ) {
35
+ utils.log( `Will publish to npm.` );
36
+ }
37
+
38
38
  const config = {
39
39
  dryRun: otherArgs.dryRun,
40
40
  ci: otherArgs.ci,
@@ -154,6 +154,7 @@ const run = async () => {
154
154
  }
155
155
  } catch ( err ) {
156
156
  console.error( 'The automated release failed with %O', err );
157
+ process.exit( 1 );
157
158
  }
158
159
  };
159
160
 
package/scripts/test.js CHANGED
@@ -45,8 +45,10 @@ const JEST_CONFIG = {
45
45
 
46
46
  args.push( '--config', JSON.stringify( JEST_CONFIG ) );
47
47
 
48
- spawn.sync( wpScripts, args, {
48
+ const result = spawn.sync( wpScripts, args, {
49
49
  cwd: modules.rootDirectory,
50
50
  stdio: 'inherit',
51
51
  env: { ...process.env, NODE_ENV: 'development' },
52
52
  } );
53
+
54
+ process.exit(result.status);
@@ -3,6 +3,6 @@ docker:
3
3
  - image: "cimg/php:<<parameters.tag>>"
4
4
  parameters:
5
5
  tag:
6
- default: 8.0-node
6
+ default: 8.3-node
7
7
  description: PHP image version
8
8
  type: string
@@ -0,0 +1,91 @@
1
+ description: >
2
+ Create translation files.
3
+
4
+ executor: default
5
+
6
+ steps:
7
+ - checkout_with_workspace
8
+ - run:
9
+ name: Check if commit author is bot
10
+ command: |
11
+ COMMIT_AUTHOR=$(git log -1 --pretty=format:'%ae')
12
+ if [ "$COMMIT_AUTHOR" = "$GITHUB_COMMITER_EMAIL" ]; then
13
+ echo "Commit was made by bot ($(git rev-parse --short HEAD)), skipping translation update"
14
+ circleci step halt
15
+ fi
16
+ - run:
17
+ name: Install WP CLI
18
+ command: |
19
+ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
20
+ chmod +x wp-cli.phar
21
+ sudo mv wp-cli.phar /usr/local/bin/wp
22
+ - run:
23
+ name: Build plugin files, so dist dir is available
24
+ command: |
25
+ npm run build || true
26
+ - run:
27
+ name: Create POT translation files
28
+ command: |
29
+ # Theme is excluded, more in https://github.com/Automattic/newspack-theme/pull/2458
30
+ if [ "$CIRCLE_PROJECT_REPONAME" = "newspack-theme" ]; then
31
+ cd ./newspack-theme
32
+ wp i18n make-pot . languages/${CIRCLE_PROJECT_REPONAME}.pot --exclude='src' --domain=${CIRCLE_PROJECT_REPONAME}
33
+ cd -
34
+ else
35
+ wp i18n make-pot . languages/${CIRCLE_PROJECT_REPONAME}.pot --domain=${CIRCLE_PROJECT_REPONAME}
36
+ fi
37
+ - run:
38
+ name: Create JSON translation files
39
+ command: |
40
+ if [ "$CIRCLE_PROJECT_REPONAME" = "newspack-theme" ]; then
41
+ cd ./newspack-theme
42
+ fi
43
+
44
+ sudo apt-get update && sudo apt-get install -y gettext
45
+
46
+ cd languages
47
+
48
+ # Create PO files from POT if they don't exist
49
+ if [ ! -f "${CIRCLE_PROJECT_REPONAME}-en_US.po" ]; then
50
+ echo "Creating ${CIRCLE_PROJECT_REPONAME}-en_US.po from POT file"
51
+ wp i18n update-po ${CIRCLE_PROJECT_REPONAME}.pot .
52
+ else
53
+ echo "${CIRCLE_PROJECT_REPONAME}-en_US.po file already exists, skipping creation"
54
+ fi
55
+
56
+ for po in *.po; do
57
+ if [ -f "$po" ]; then
58
+ echo "Processing file $po …"
59
+ # Update translations according to the new POT file
60
+ msgmerge $po $CIRCLE_PROJECT_REPONAME.pot -o $po.out
61
+ mv $po.out $po
62
+ msgfmt $po -o $(basename $po .po).mo
63
+ # no-purge since we need the JS translations for the next run
64
+ wp i18n make-json --no-purge $po .
65
+ fi
66
+ done
67
+ - run:
68
+ name: Commit translation files
69
+ command: |
70
+ if [ "$CIRCLE_PROJECT_REPONAME" = "newspack-theme" ]; then
71
+ cd ./newspack-theme
72
+ fi
73
+ if [ -d "languages" ]; then
74
+ LINES_CHANGED=$(git diff --numstat languages/ | awk '{sum += $1 + $2} END {print sum}')
75
+ # If no existing files were changed, check for new files
76
+ if [ -z "$LINES_CHANGED" ] || [ "$LINES_CHANGED" -eq 0 ]; then
77
+ LINES_CHANGED=$(git ls-files --others --exclude-standard languages/ | xargs wc -l 2>/dev/null | tail -1 | awk '{print $1}')
78
+ fi
79
+ else
80
+ LINES_CHANGED=0
81
+ fi
82
+ LINES_CHANGED=${LINES_CHANGED:-0}
83
+ echo "Lines changed in languages/: $LINES_CHANGED"
84
+ if [ "$LINES_CHANGED" -gt 3 ]; then
85
+ git config user.email "$GITHUB_COMMITER_EMAIL"
86
+ git config user.name "$GIT_COMMITTER_NAME"
87
+ git remote set-url origin https://$GITHUB_TOKEN@github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git
88
+ git add languages/
89
+ git commit -m "chore: update translation files [skip ci]"
90
+ git push origin $CIRCLE_BRANCH
91
+ fi
@@ -1,7 +1,7 @@
1
1
  description: >
2
2
  Lint PHP files.
3
3
 
4
- executor: php-81
4
+ executor: default
5
5
 
6
6
  steps:
7
7
  - checkout
@@ -2,7 +2,7 @@ description: >
2
2
  Run PHP tests.
3
3
 
4
4
  docker:
5
- - image: cimg/php:8.0
5
+ - image: cimg/php:8.3
6
6
  - image: circleci/mysql:5.6.50
7
7
 
8
8
  environment: