diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 4c91947f..8cedfad2 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -71,15 +71,10 @@ on: # Build options. plugin-directory: - description: Directory of the plugin, if not in the root of the repository. If provided, package-manager must also be provided. + description: Directory of the plugin, if not in the root of the repository. type: string required: false default: . - package-manager: - description: The package manager to use. - type: string - required: false - default: "" npm-registry-auth: description: | Whether to authenticate to the npm registry in Google Artifact Registry. @@ -346,13 +341,12 @@ jobs: ci: name: CI - uses: grafana/plugin-ci-workflows/.github/workflows/ci.yml@main + uses: grafana/plugin-ci-workflows/.github/workflows/ci.yml@jackw/pm-detect # zizmor: ignore[unpinned-uses] needs: - setup with: branch: ${{ inputs.branch }} plugin-directory: ${{ inputs.plugin-directory }} - package-manager: ${{ inputs.package-manager }} npm-registry-auth: ${{ inputs.npm-registry-auth }} go-version: ${{ inputs.go-version }} go-setup-caching: ${{ inputs.go-setup-caching }} @@ -563,7 +557,7 @@ jobs: ENVIRONMENT: ${{ matrix.environment }} - name: Check and create stub - uses: grafana/plugin-ci-workflows/actions/plugins/publish/check-and-create-stub@main + uses: grafana/plugin-ci-workflows/actions/plugins/publish/check-and-create-stub@jackw/pm-detect # zizmor: ignore[unpinned-uses] if: ${{ matrix.environment != 'prod' }} with: plugin-id: ${{ fromJSON(needs.ci.outputs.plugin).id }} @@ -572,13 +566,13 @@ jobs: gcloud-auth-token: ${{ steps.gcloud.outputs.id_token }} - name: Check artifact ZIP(s) - uses: grafana/plugin-ci-workflows/actions/plugins/publish/check-artifacts@main + uses: grafana/plugin-ci-workflows/actions/plugins/publish/check-artifacts@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: zips: ${{ needs.upload-to-gcs-release.outputs.gcs-zip-urls }} plugin-id: ${{ fromJSON(needs.ci.outputs.plugin).id }} - name: Publish to catalog - uses: grafana/plugin-ci-workflows/actions/plugins/publish/publish@main + uses: grafana/plugin-ci-workflows/actions/plugins/publish/publish@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: zips: ${{ needs.upload-to-gcs-release.outputs.gcs-zip-urls }} environment: ${{ matrix.environment }} @@ -883,7 +877,7 @@ jobs: owner: ${{ github.repository_owner }} - name: Publish docs - uses: grafana/plugin-ci-workflows/actions/plugins/docs/publish@main + uses: grafana/plugin-ci-workflows/actions/plugins/docs/publish@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: id: ${{ fromJSON(needs.ci.outputs.plugin).id }} version: ${{ fromJSON(needs.ci.outputs.plugin).version }} @@ -920,7 +914,7 @@ jobs: - name: Parse changelog id: changelog - uses: grafana/plugin-ci-workflows/actions/plugins/changelog@main + uses: grafana/plugin-ci-workflows/actions/plugins/changelog@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: changelog-path: ${{ inputs.plugin-directory }}/CHANGELOG.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8abd3600..1c05c4d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,15 +41,10 @@ on: # Build options. plugin-directory: - description: Directory of the plugin, if not in the root of the repository. If provided, package-manager must also be provided. + description: Directory of the plugin, if not in the root of the repository. type: string required: false default: . - package-manager: - description: The package manager to use. - type: string - required: false - default: "" frontend-secrets: description: The secrets to use within frontend steps type: string @@ -277,7 +272,7 @@ jobs: return o - name: Setup - uses: grafana/plugin-ci-workflows/actions/plugins/setup@main + uses: grafana/plugin-ci-workflows/actions/plugins/setup@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: go-version: ${{ inputs.go-version || env.DEFAULT_GO_VERSION }} node-version: ${{ inputs.node-version || env.DEFAULT_NODE_VERSION }} @@ -339,16 +334,15 @@ jobs: working-directory: ${{ inputs.plugin-directory }} - name: Test and build frontend - uses: grafana/plugin-ci-workflows/actions/plugins/frontend@main + uses: grafana/plugin-ci-workflows/actions/plugins/frontend@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: - package-manager: ${{ inputs.package-manager }} plugin-directory: ${{ inputs.plugin-directory }} secrets: ${{ (fromJson(steps.workflow-context.outputs.result).isTrusted && inputs.frontend-secrets != '') && inputs.frontend-secrets || '' }} npm-registry-auth: ${{ inputs.npm-registry-auth }} - name: Test and build backend if: ${{ steps.check-for-backend.outputs.has-backend == 'true' }} - uses: grafana/plugin-ci-workflows/actions/plugins/backend@main + uses: grafana/plugin-ci-workflows/actions/plugins/backend@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: github-token: ${{ steps.generate-github-token.outputs.token }} plugin-directory: ${{ inputs.plugin-directory }} @@ -356,7 +350,7 @@ jobs: - name: Package universal ZIP id: universal-zip - uses: grafana/plugin-ci-workflows/actions/plugins/package@main + uses: grafana/plugin-ci-workflows/actions/plugins/package@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: universal: "true" dist-folder: dist @@ -366,7 +360,7 @@ jobs: - name: Package os/arch ZIPs id: os-arch-zips - uses: grafana/plugin-ci-workflows/actions/plugins/package@main + uses: grafana/plugin-ci-workflows/actions/plugins/package@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: universal: "false" dist-folder: dist @@ -376,7 +370,7 @@ jobs: - name: Trufflehog secrets scanning if: ${{ inputs.run-trufflehog == true }} - uses: grafana/plugin-ci-workflows/actions/plugins/trufflehog@main + uses: grafana/plugin-ci-workflows/actions/plugins/trufflehog@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: trufflehog-version: ${{ inputs.trufflehog-version || env.DEFAULT_TRUFFLEHOG_VERSION }} folder: dist-artifacts @@ -446,11 +440,11 @@ jobs: shell: bash - name: Test docs - uses: grafana/plugin-ci-workflows/actions/plugins/docs/test@main + uses: grafana/plugin-ci-workflows/actions/plugins/docs/test@jackw/pm-detect # zizmor: ignore[unpinned-uses] playwright: name: Playwright E2E tests - uses: grafana/plugin-ci-workflows/.github/workflows/playwright.yml@main + uses: grafana/plugin-ci-workflows/.github/workflows/playwright.yml@jackw/pm-detect # zizmor: ignore[unpinned-uses] if: ${{ inputs.run-playwright == true }} needs: - test-and-build @@ -472,7 +466,7 @@ jobs: playwright-docker: name: Plugins - Dockerized Playwright E2E tests - uses: grafana/plugin-ci-workflows/.github/workflows/playwright-docker.yml@main + uses: grafana/plugin-ci-workflows/.github/workflows/playwright-docker.yml@jackw/pm-detect # zizmor: ignore[unpinned-uses] if: ${{ inputs.run-playwright-docker == true }} needs: - test-and-build diff --git a/.github/workflows/playwright-docker.yml b/.github/workflows/playwright-docker.yml index cc867f7e..ba6aa1b0 100644 --- a/.github/workflows/playwright-docker.yml +++ b/.github/workflows/playwright-docker.yml @@ -71,7 +71,7 @@ jobs: - name: Resolve Grafana E2E versions id: resolve-versions - uses: grafana/plugin-actions/e2e-version@main + uses: grafana/plugin-actions/e2e-version@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: skip-grafana-dev-image: ${{ inputs.skip-grafana-dev-image }} version-resolver-type: ${{ inputs.version-resolver-type }} @@ -136,7 +136,7 @@ jobs: DOCKER_COMPOSE_FILE: ${{ inputs.grafana-compose-file }} - name: Wait for Grafana to start - uses: grafana/plugin-actions/wait-for-grafana@main + uses: grafana/plugin-actions/wait-for-grafana@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: url: "${{ inputs.grafana-url }}" diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index bf74c6cc..dc2f5ee7 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -89,7 +89,7 @@ jobs: - name: Resolve Grafana E2E versions id: resolve-versions - uses: grafana/plugin-actions/e2e-version@main + uses: grafana/plugin-actions/e2e-version@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: skip-grafana-dev-image: ${{ inputs.skip-grafana-dev-image }} version-resolver-type: ${{ inputs.version-resolver-type }} @@ -110,11 +110,24 @@ jobs: with: persist-credentials: false + - name: Detect package manager + id: package-manager + # TODO: Fix this once we have a version of the package-manager-detect action + uses: grafana/plugin-actions/package-manager-detect@jackw/pm-detect # zizmor: ignore[unpinned-uses] + with: + working-directory: ${{ inputs.plugin-directory }} + + - name: Install pnpm + if: steps.package-manager.outputs.name == 'pnpm' + uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 + - name: Setup Node.js environment uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: node-version: ${{ inputs.node-version }} node-version-file: ${{ inputs.plugin-directory }}/.nvmrc + cache: ${{ steps.package-manager.outputs.name }} + cache-dependency-path: ${{ steps.package-manager.outputs.lockFilePath }} - name: Login to Google Cloud if: inputs.npm-registry-auth == true @@ -131,13 +144,7 @@ jobs: run: GOOGLE_APPLICATION_CREDENTIALS=${{ env.GOOGLE_APPLICATION_CREDENTIALS }} npx google-artifactregistry-auth --credential-config ./.npmrc - name: Install npm dependencies - # TODO: find a better way - run: | - if [ -f yarn.lock ]; then - yarn install --frozen-lockfile - else - npm ci - fi + run: ${{ steps.package-manager.outputs.frozenInstallCmd }} shell: bash working-directory: ${{ inputs.plugin-directory }} @@ -173,7 +180,8 @@ jobs: key: playwright-${{ steps.version.outputs.version }} - name: Install Playwright Browsers - run: npx playwright install --with-deps chromium + run: ${{ steps.package-manager.outputs.execCmd }} playwright install --with-deps chromium + shell: bash - name: Download GitHub artifact uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 @@ -222,13 +230,13 @@ jobs: DOCKER_COMPOSE_FILE: ${{ inputs.docker-compose-file }} - name: Wait for Grafana to start - uses: grafana/plugin-actions/wait-for-grafana@main + uses: grafana/plugin-actions/wait-for-grafana@jackw/pm-detect # zizmor: ignore[unpinned-uses] with: url: "${{ inputs.grafana-url }}" - name: Run Playwright tests id: run-tests - run: npx playwright test --config "${PLAYWRIGHT_CONFIG}" + run: ${{ steps.package-manager.outputs.execCmd }} playwright test --config "${PLAYWRIGHT_CONFIG}" env: PLAYWRIGHT_CONFIG: ${{ inputs.playwright-config }} GRAFANA_VERSION: ${{ matrix.GRAFANA_IMAGE.VERSION }} diff --git a/actions/plugins/backend/action.yml b/actions/plugins/backend/action.yml index b257371d..0a007866 100644 --- a/actions/plugins/backend/action.yml +++ b/actions/plugins/backend/action.yml @@ -6,7 +6,7 @@ inputs: description: GitHub token for downloading dependencies from private repos, if necessary required: true plugin-directory: - description: Directory of the plugin, if not in the root of the repository. If provided, package-manager must also be provided. + description: Directory of the plugin, if not in the root of the repository. required: false default: . secrets: diff --git a/actions/plugins/frontend/action.yml b/actions/plugins/frontend/action.yml index bdab5617..e5b5e1b0 100644 --- a/actions/plugins/frontend/action.yml +++ b/actions/plugins/frontend/action.yml @@ -3,13 +3,9 @@ description: Tests, lints, typechecks and builds the frontend. inputs: plugin-directory: - description: Directory of the plugin, if not in the root of the repository. If provided, package-manager must also be provided. + description: Directory of the plugin, if not in the root of the repository. required: false default: . - package-manager: - description: The package manager to use. - required: false - default: "" secrets: required: false type: string @@ -45,40 +41,37 @@ runs: working-directory: ${{ inputs.plugin-directory }} run: GOOGLE_APPLICATION_CREDENTIALS=${{ env.GOOGLE_APPLICATION_CREDENTIALS }} npx google-artifactregistry-auth --credential-config ./.npmrc + - name: Detect package manager + id: package-manager + # TODO: Fix this once we have a version of the package-manager-detect action + uses: grafana/plugin-actions/package-manager-detect@jackw/pm-detect # zizmor: ignore[unpinned-uses] + with: + working-directory: ${{ inputs.plugin-directory }} + - name: Install dependencies shell: bash working-directory: ${{ inputs.plugin-directory }} - run: ${{ github.action_path }}/pm.sh install - env: - PACKAGE_MANAGER: ${{ inputs.package-manager }} + run: ${{ steps.package-manager.outputs.frozenInstallCmd }} - name: Lint shell: bash working-directory: ${{ inputs.plugin-directory }} - run: ${{ github.action_path }}/pm.sh lint - env: - PACKAGE_MANAGER: ${{ inputs.package-manager }} + run: ${{ steps.package-manager.outputs.runCmd }} lint - name: Typecheck shell: bash working-directory: ${{ inputs.plugin-directory }} - run: ${{ github.action_path }}/pm.sh typecheck - env: - PACKAGE_MANAGER: ${{ inputs.package-manager }} + run: ${{ steps.package-manager.outputs.runCmd }} typecheck - name: Test shell: bash working-directory: ${{ inputs.plugin-directory }} - run: ${{ github.action_path }}/pm.sh test:ci - env: - PACKAGE_MANAGER: ${{ inputs.package-manager }} + run: ${{ steps.package-manager.outputs.runCmd }} test:ci - name: Build shell: bash working-directory: ${{ inputs.plugin-directory }} - run: ${{ github.action_path }}/pm.sh build - env: - PACKAGE_MANAGER: ${{ inputs.package-manager }} + run: ${{ steps.package-manager.outputs.runCmd }} build # The action should end up with a dist/ folder, but if the working directory is not the root of the repo, # we need to copy the dist/ folder to the root of the repo. diff --git a/actions/plugins/frontend/pm.sh b/actions/plugins/frontend/pm.sh deleted file mode 100755 index fc7cea6f..00000000 --- a/actions/plugins/frontend/pm.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -# Check if command argument is provided -if [ "$1" = "" ]; then - echo "Please provide a command to run." - exit 1 -fi - -install_pnpm_if_not_present() { - if ! command -v pnpm &> /dev/null - then - echo "pnpm could not be found, installing..." - npm install -g pnpm - fi -} - -# Use provided package manager if set in PACKAGE_MANAGER environment variable -if [ -n "$PACKAGE_MANAGER" ]; then - pm="$PACKAGE_MANAGER" -# Detect the package manager -elif [ -f yarn.lock ]; then - pm="yarn" -elif [ -f pnpm-lock.yaml ]; then - install_pnpm_if_not_present - pm="pnpm" -elif [ -f package-lock.json ]; then - pm="npm" -else - echo "No recognized package manager found in this project." - exit 1 -fi - -# Run the provided command with the detected package manager -echo "Running '$1' with $pm..." -if [ "$1" = "install" ]; then - "$pm" install -else - "$pm" run "$1" -fi diff --git a/actions/plugins/setup/action.yml b/actions/plugins/setup/action.yml index e83b7b4d..3a0d5182 100644 --- a/actions/plugins/setup/action.yml +++ b/actions/plugins/setup/action.yml @@ -23,11 +23,22 @@ inputs: runs: using: composite steps: + - name: Detect package manager + id: package-manager + # TODO: Fix this once we have a version of the package-manager-detect action + uses: grafana/plugin-actions/package-manager-detect@jackw/pm-detect + + - name: Install pnpm + if: steps.package-manager.outputs.name == 'pnpm' + uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 + - name: Node uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: node-version: "${{ inputs.node-version }}" node-version-file: "${{ inputs.node-version-file }}" + cache: ${{ steps.package-manager.outputs.name }} + cache-dependency-path: ${{ steps.package-manager.outputs.lockFilePath }} - name: Go uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0