Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Add user agent and trailing slash (#1572)
Browse files Browse the repository at this point in the history
* Add user agent and trailing slash

* Download locales only once per workflow

* Update src/locales/scripts/create-wp-locale-list.js

Co-authored-by: Krystle Salazar <krystle.salazar@automattic.com>

* Update src/locales/scripts/get-translations.js

Co-authored-by: Krystle Salazar <krystle.salazar@automattic.com>

* Update src/locales/scripts/get-translations-status.js

Co-authored-by: Krystle Salazar <krystle.salazar@automattic.com>

* Extract network-service from locale scripts

To enable setting the user agent string in a single place while keeping the scripts independent of each other

* Update src/locales/scripts/network-service.js

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* Simplify axios module

Co-authored-by: Krystle Salazar <krystle.salazar@automattic.com>
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 19, 2022
1 parent ed644b4 commit a3fdb15
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
12 changes: 9 additions & 3 deletions .github/actions/setup-node-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
install:
default: true
description: Whether to install dependencies.
downloadLocales:
required: false
default: "false"
description: Whether to download locales artifact.

runs:
using: "composite"
Expand Down Expand Up @@ -32,6 +36,8 @@ runs:
shell: bash
run: "pnpm install"

- name: Get locales
shell: bash
run: "pnpm i18n"
- uses: actions/download-artifact@v3
if: inputs.downloadLocales == 'true'
with:
name: locales
path: src/locales
42 changes: 41 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,51 @@ concurrency:
cancel-in-progress: true

jobs:
update-locales:
name: Update locales
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-node-env

- name: Create locales artifact
run: "pnpm i18n"

- name: Upload locales artifact
uses: actions/upload-artifact@v3
with:
path: src/locales
name: locales

types:
name: Check types
runs-on: ubuntu-latest
needs:
- update-locales

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-node-env
with:
downloadLocales: true

- name: Check types
run: pnpm types

lint:
name: Lint files
runs-on: ubuntu-latest
needs:
- update-locales

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-node-env
with:
downloadLocales: true

- name: Lint with ESLint and Prettier
run: pnpm lint
Expand All @@ -54,11 +79,15 @@ jobs:
name: Unit tests
runs-on: ubuntu-latest

needs:
- update-locales

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-node-env

with:
downloadLocales: true
- name: Run unit tests
run: pnpm test:unit

Expand Down Expand Up @@ -90,11 +119,14 @@ jobs:
runs-on: ubuntu-latest
needs:
- build
- update-locales

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-node-env
with:
downloadLocales: true

- name: Run Nuxt Playwright tests
run: pnpm test:playwright
Expand All @@ -108,11 +140,15 @@ jobs:
storybook-playwright:
name: Storybook Playwright tests
runs-on: ubuntu-latest
needs:
- update-locales

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-node-env
with:
downloadLocales: true

- name: Run Storybook Playwright tests
run: pnpm test:storybook
Expand Down Expand Up @@ -150,11 +186,15 @@ jobs:
storybook:
name: Check Storybook build
runs-on: ubuntu-latest
needs:
- update-locales

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-node-env
with:
downloadLocales: true

- name: Run Storybook smoke-test
run: pnpm storybook:smoke
Expand Down
8 changes: 8 additions & 0 deletions src/locales/scripts/axios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const axios = require('axios')

const userAgent =
'Openverse/0.1 (https://wordpress.org/openverse; openverse@wordpress.org)'

module.exports = axios.create({
headers: { 'User-Agent': userAgent },
})
2 changes: 1 addition & 1 deletion src/locales/scripts/create-wp-locale-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This script extracts data for locales available in GlotPress and translate.wp.or

const fs = require('fs')

const axios = require('axios')
const axios = require('./axios')

const { addFetchedTranslationStatus } = require('./get-translations-status')

Expand Down
5 changes: 3 additions & 2 deletions src/locales/scripts/get-translations-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* Update the GP locales object with this data, and removes any of the GP
* locales that are not available on translate.wordpress.org.
*/
const axios = require('axios')
const parser = require('node-html-parser')

const baseUrl = `https://translate.wordpress.org/projects/meta/openverse`
const axios = require('./axios')

const baseUrl = 'https://translate.wordpress.org/projects/meta/openverse/'

function parseRow(row, locales) {
const cells = row.querySelectorAll('td')
Expand Down
2 changes: 1 addition & 1 deletion src/locales/scripts/get-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const { writeFile } = require('fs/promises')
const os = require('os')

const axios = require('axios')
const axios = require('./axios')

const jed1xJsonToJson = require('./jed1x-json-to-json')
const localeJSON = require('./wp-locales.json')
Expand Down

0 comments on commit a3fdb15

Please sign in to comment.