From 6462619d501db1f6033ec043e1a09e33b5f9f562 Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Tue, 16 Jul 2024 09:58:22 +0200 Subject: [PATCH 1/6] feat: Add linter for Nimbus file --- .github/workflows/nimbus_linter.yaml | 19 +++++++++++++++++++ .github/workflows/reference_linter.yaml | 2 +- scripts/lint-nimbus-file.sh | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/nimbus_linter.yaml create mode 100644 scripts/lint-nimbus-file.sh diff --git a/.github/workflows/nimbus_linter.yaml b/.github/workflows/nimbus_linter.yaml new file mode 100644 index 00000000000..0b3cae7ea14 --- /dev/null +++ b/.github/workflows/nimbus_linter.yaml @@ -0,0 +1,19 @@ +name: Lint Reference Files +on: + push: + pull_request: + workflow_dispatch: +jobs: + l10n-lint: + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v4 + - name: Set up Python 3 + uses: actions/setup-python@v5 + with: + python-version: '3.10' + cache: 'pip' + - name: Lint Nimbus file + run: | + sh /scripts/lint-nimbus-file.sh diff --git a/.github/workflows/reference_linter.yaml b/.github/workflows/reference_linter.yaml index 173b7180b3d..1ae111f208b 100644 --- a/.github/workflows/reference_linter.yaml +++ b/.github/workflows/reference_linter.yaml @@ -1,4 +1,4 @@ -name: Lint Reference Files +name: Lint nimbus.yaml on: push: pull_request: diff --git a/scripts/lint-nimbus-file.sh b/scripts/lint-nimbus-file.sh new file mode 100644 index 00000000000..573af27b58c --- /dev/null +++ b/scripts/lint-nimbus-file.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +TARGET_PATH=/tmp/nimbus-cli +NIMBUS_INSTALL_REMOTE_PATH=https://raw.githubusercontent.com/mozilla/application-services/main/install-nimbus-cli.sh +NIMBUS_INSTALL_LOCAL_PATH=$TARGET_PATH/install.sh + +if [ -d $TARGET_PATH ]; then + echo "Directory for \`nimbus-cli\` already exists: $TARGET_PATH" +else + echo "Create directory for \`nimbus-cli\`: $TARGET_PATH" + mkdir -p $TARGET_PATH + + echo "Download \`nimbus-cli\` installer from $NIMBUS_INSTALL_REMOTE_PATH to $TARGET_PATH" + curl --proto '=https' --tlsv1.2 -sSf -o "$NIMBUS_INSTALL_LOCAL_PATH" "$NIMBUS_INSTALL_REMOTE_PATH" + + echo "Install \`nimbus-cli\`" + bash $NIMBUS_INSTALL_LOCAL_PATH --directory $TARGET_PATH +fi + +echo "Lint nimbus.yaml" +$TARGET_PATH/nimbus-cli fml -- validate config/nimbus.yaml From 23a99b2841a0aeba3e0480e25e6d482bade1e8fa Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Wed, 24 Jul 2024 16:07:43 +0200 Subject: [PATCH 2/6] chore: Update nimbus-validate Github workflow --- .github/workflows/nimbus_linter.yaml | 19 ------------------- .github/workflows/reference_linter.yaml | 2 +- package.json | 5 +++-- ...nimbus-file.sh => validate-nimbus-file.sh} | 0 4 files changed, 4 insertions(+), 22 deletions(-) delete mode 100644 .github/workflows/nimbus_linter.yaml rename scripts/{lint-nimbus-file.sh => validate-nimbus-file.sh} (100%) diff --git a/.github/workflows/nimbus_linter.yaml b/.github/workflows/nimbus_linter.yaml deleted file mode 100644 index 0b3cae7ea14..00000000000 --- a/.github/workflows/nimbus_linter.yaml +++ /dev/null @@ -1,19 +0,0 @@ -name: Lint Reference Files -on: - push: - pull_request: - workflow_dispatch: -jobs: - l10n-lint: - runs-on: ubuntu-latest - steps: - - name: Clone repository - uses: actions/checkout@v4 - - name: Set up Python 3 - uses: actions/setup-python@v5 - with: - python-version: '3.10' - cache: 'pip' - - name: Lint Nimbus file - run: | - sh /scripts/lint-nimbus-file.sh diff --git a/.github/workflows/reference_linter.yaml b/.github/workflows/reference_linter.yaml index 1ae111f208b..173b7180b3d 100644 --- a/.github/workflows/reference_linter.yaml +++ b/.github/workflows/reference_linter.yaml @@ -1,4 +1,4 @@ -name: Lint nimbus.yaml +name: Lint Reference Files on: push: pull_request: diff --git a/package.json b/package.json index 94dc65abd0c..0780af307b3 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "build": "npm run get-location-data && npm run build-glean && npm run build-nimbus && next build && npm run build-cronjobs", "cloudrun": "npm run db:migrate && npm start", "start": "next start", - "lint": "stylelint '**/*.scss' && prettier --check './src' && next lint --max-warnings=0 && tsc -p tsconfig.json --noEmit", + "lint": "stylelint '**/*.scss' && prettier --check './src' && next lint --max-warnings=0 && tsc -p tsconfig.json --noEmit && npm run validate-nimbus", "fix": "prettier --write './src' && next lint --fix && stylelint --fix '**/*.scss'", "test": "npm run build-nimbus && jest", "e2e": "playwright test src/e2e/", @@ -48,7 +48,8 @@ "build-glean-types": "node src/scripts/build/gleanTypes.js", "build-glean-docs": "npm run build-glean-frontend-docs && npm run build-glean-backend-docs", "build-glean-frontend-docs": "glean translate src/telemetry/metrics.yaml --format markdown --output docs/telemetry/frontent", - "build-glean-backend-docs": "glean translate src/telemetry/backend-metrics.yaml --format markdown --output docs/telemetry/backend" + "build-glean-backend-docs": "glean translate src/telemetry/backend-metrics.yaml --format markdown --output docs/telemetry/backend", + "validate-nimbus": "sh scripts/validate-nimbus-file.sh" }, "repository": { "type": "git", diff --git a/scripts/lint-nimbus-file.sh b/scripts/validate-nimbus-file.sh similarity index 100% rename from scripts/lint-nimbus-file.sh rename to scripts/validate-nimbus-file.sh From 43b653b0846d7313ceba8c61c510605682a413f6 Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Wed, 24 Jul 2024 18:59:52 +0200 Subject: [PATCH 3/6] chore: Handle potential whitespaces in TARGET_PATH --- scripts/validate-nimbus-file.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/validate-nimbus-file.sh b/scripts/validate-nimbus-file.sh index 573af27b58c..dd06e5eb045 100644 --- a/scripts/validate-nimbus-file.sh +++ b/scripts/validate-nimbus-file.sh @@ -4,7 +4,7 @@ TARGET_PATH=/tmp/nimbus-cli NIMBUS_INSTALL_REMOTE_PATH=https://raw.githubusercontent.com/mozilla/application-services/main/install-nimbus-cli.sh NIMBUS_INSTALL_LOCAL_PATH=$TARGET_PATH/install.sh -if [ -d $TARGET_PATH ]; then +if [ -d "${TARGET_PATH}" ]; then echo "Directory for \`nimbus-cli\` already exists: $TARGET_PATH" else echo "Create directory for \`nimbus-cli\`: $TARGET_PATH" From e55459c7cd2a5098f6f456eacb16d89fd9e66b5f Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Wed, 24 Jul 2024 19:31:25 +0200 Subject: [PATCH 4/6] chore: Explicitly check if nimbus-cli has been downloaded and installed --- scripts/validate-nimbus-file.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/validate-nimbus-file.sh b/scripts/validate-nimbus-file.sh index dd06e5eb045..cb796ad5a29 100644 --- a/scripts/validate-nimbus-file.sh +++ b/scripts/validate-nimbus-file.sh @@ -9,10 +9,18 @@ if [ -d "${TARGET_PATH}" ]; then else echo "Create directory for \`nimbus-cli\`: $TARGET_PATH" mkdir -p $TARGET_PATH +fi +if [ -f "${NIMBUS_INSTALL_LOCAL_PATH}" ]; then + echo "Skip download of \`nimbus-cli\` installer" +else echo "Download \`nimbus-cli\` installer from $NIMBUS_INSTALL_REMOTE_PATH to $TARGET_PATH" curl --proto '=https' --tlsv1.2 -sSf -o "$NIMBUS_INSTALL_LOCAL_PATH" "$NIMBUS_INSTALL_REMOTE_PATH" +fi +if command -v "${TARGET_PATH}/nimbus-cli"; then + echo "Skip installation of \`nimbus-cli\`" +else echo "Install \`nimbus-cli\`" bash $NIMBUS_INSTALL_LOCAL_PATH --directory $TARGET_PATH fi From c153dca5b67d535d3955bc69d55ab35104d4198c Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Fri, 26 Jul 2024 12:16:06 +0200 Subject: [PATCH 5/6] chore: Move validate-nimbus-file.sh into src/scripts/ --- package.json | 2 +- {scripts => src/scripts}/validate-nimbus-file.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {scripts => src/scripts}/validate-nimbus-file.sh (100%) diff --git a/package.json b/package.json index 0780af307b3..6cdd963bf57 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "build-glean-docs": "npm run build-glean-frontend-docs && npm run build-glean-backend-docs", "build-glean-frontend-docs": "glean translate src/telemetry/metrics.yaml --format markdown --output docs/telemetry/frontent", "build-glean-backend-docs": "glean translate src/telemetry/backend-metrics.yaml --format markdown --output docs/telemetry/backend", - "validate-nimbus": "sh scripts/validate-nimbus-file.sh" + "validate-nimbus": "sh src/scripts/validate-nimbus-file.sh" }, "repository": { "type": "git", diff --git a/scripts/validate-nimbus-file.sh b/src/scripts/validate-nimbus-file.sh similarity index 100% rename from scripts/validate-nimbus-file.sh rename to src/scripts/validate-nimbus-file.sh From dcc316be86feb7bb2a3981e8a1b382b3fd88aa21 Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Fri, 26 Jul 2024 12:20:02 +0200 Subject: [PATCH 6/6] chore: Check if nimbus-cli is installed first --- src/scripts/validate-nimbus-file.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/scripts/validate-nimbus-file.sh b/src/scripts/validate-nimbus-file.sh index cb796ad5a29..3cb52264dc7 100644 --- a/src/scripts/validate-nimbus-file.sh +++ b/src/scripts/validate-nimbus-file.sh @@ -4,23 +4,23 @@ TARGET_PATH=/tmp/nimbus-cli NIMBUS_INSTALL_REMOTE_PATH=https://raw.githubusercontent.com/mozilla/application-services/main/install-nimbus-cli.sh NIMBUS_INSTALL_LOCAL_PATH=$TARGET_PATH/install.sh -if [ -d "${TARGET_PATH}" ]; then - echo "Directory for \`nimbus-cli\` already exists: $TARGET_PATH" -else - echo "Create directory for \`nimbus-cli\`: $TARGET_PATH" - mkdir -p $TARGET_PATH -fi - -if [ -f "${NIMBUS_INSTALL_LOCAL_PATH}" ]; then - echo "Skip download of \`nimbus-cli\` installer" -else - echo "Download \`nimbus-cli\` installer from $NIMBUS_INSTALL_REMOTE_PATH to $TARGET_PATH" - curl --proto '=https' --tlsv1.2 -sSf -o "$NIMBUS_INSTALL_LOCAL_PATH" "$NIMBUS_INSTALL_REMOTE_PATH" -fi - if command -v "${TARGET_PATH}/nimbus-cli"; then echo "Skip installation of \`nimbus-cli\`" else + if [ -d "${TARGET_PATH}" ]; then + echo "Directory for \`nimbus-cli\` already exists: $TARGET_PATH" + else + echo "Create directory for \`nimbus-cli\`: $TARGET_PATH" + mkdir -p $TARGET_PATH + fi + + if [ -f "${NIMBUS_INSTALL_LOCAL_PATH}" ]; then + echo "Skip download of \`nimbus-cli\` installer" + else + echo "Download \`nimbus-cli\` installer from $NIMBUS_INSTALL_REMOTE_PATH to $TARGET_PATH" + curl --proto '=https' --tlsv1.2 -sSf -o "$NIMBUS_INSTALL_LOCAL_PATH" "$NIMBUS_INSTALL_REMOTE_PATH" + fi + echo "Install \`nimbus-cli\`" bash $NIMBUS_INSTALL_LOCAL_PATH --directory $TARGET_PATH fi