From 0a4c6d6c488759aa73ec4cc50209a5ed44894f3a Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Tue, 6 Sep 2022 16:58:50 +0200 Subject: [PATCH] Refactor UI publishing and polish tests (#11267) Signed-off-by: Julien Pivotto Signed-off-by: Julien Pivotto --- .github/actions/publish_images/action.yml | 5 -- .github/actions/publish_main/action.yml | 4 + .github/actions/publish_release/action.yml | 4 + .../actions/publish_release_image/action.yml | 5 -- .github/workflows/{test.yml => ci.yml} | 80 +++++++++++++++++-- .github/workflows/codeql-analysis.yml | 5 +- .github/workflows/fuzzing.yml | 2 +- .github/workflows/golangci-lint.yml | 30 ------- .github/workflows/ui_build_and_release.yml | 45 ----------- 9 files changed, 83 insertions(+), 97 deletions(-) rename .github/workflows/{test.yml => ci.yml} (61%) delete mode 100644 .github/workflows/golangci-lint.yml delete mode 100644 .github/workflows/ui_build_and_release.yml diff --git a/.github/actions/publish_images/action.yml b/.github/actions/publish_images/action.yml index fe5c481b9..bc17eb7d9 100644 --- a/.github/actions/publish_images/action.yml +++ b/.github/actions/publish_images/action.yml @@ -27,11 +27,6 @@ inputs: runs: using: composite steps: - - name: Download all workflow run artifacts - uses: actions/download-artifact@v3 - with: - name: artifact - - uses: ./.github/actions/setup_environment - if: inputs.dockerfile_path != '' run: echo "export DOCKERFILE_PATH=${{ inputs.dockerfile_path }}" >> /tmp/tmp-profile shell: bash diff --git a/.github/actions/publish_main/action.yml b/.github/actions/publish_main/action.yml index b8d523e3c..e19ed9f5f 100644 --- a/.github/actions/publish_main/action.yml +++ b/.github/actions/publish_main/action.yml @@ -26,6 +26,10 @@ runs: - uses: ./.github/actions/setup_environment with: enable_docker_multibuild: true + - name: Download all workflow run artifacts + uses: actions/download-artifact@v3 + with: + name: artifact - uses: ./.github/actions/publish_images if: inputs.docker_hub_organization != '' && inputs.docker_hub_login != '' with: diff --git a/.github/actions/publish_release/action.yml b/.github/actions/publish_release/action.yml index 571265eda..fdc6a4bd7 100644 --- a/.github/actions/publish_release/action.yml +++ b/.github/actions/publish_release/action.yml @@ -26,6 +26,10 @@ runs: - uses: ./.github/actions/setup_environment with: enable_docker_multibuild: true + - name: Download all workflow run artifacts + uses: actions/download-artifact@v3 + with: + name: artifact - run: promu crossbuild tarballs shell: bash - run: promu checksum .tarballs diff --git a/.github/actions/publish_release_image/action.yml b/.github/actions/publish_release_image/action.yml index 0a165e9e4..fab19f3fd 100644 --- a/.github/actions/publish_release_image/action.yml +++ b/.github/actions/publish_release_image/action.yml @@ -27,11 +27,6 @@ inputs: runs: using: composite steps: - - name: Download all workflow run artifacts - uses: actions/download-artifact@v3 - with: - name: artifact - - uses: ./.github/actions/setup_environment - if: inputs.dockerfile_path != '' run: echo "export DOCKERFILE_PATH=${{ inputs.dockerfile_path }}" >> /tmp/tmp-profile shell: bash diff --git a/.github/workflows/test.yml b/.github/workflows/ci.yml similarity index 61% rename from .github/workflows/test.yml rename to .github/workflows/ci.yml index 34934e1f6..3511e7e02 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,11 @@ --- -name: tests +name: CI on: pull_request: push: jobs: test_go: + name: Go tests runs-on: ubuntu-latest # Whenever the Go version is updated here, .promu.yml # should also be updated. @@ -22,6 +23,7 @@ jobs: version: "3.15.8" test_ui: + name: UI tests runs-on: ubuntu-latest # Whenever the Go version is updated here, .promu.yml # should also be updated. @@ -42,6 +44,7 @@ jobs: directory: .tarballs test_windows: + name: Go tests on Windows runs-on: windows-latest steps: - uses: actions/checkout@v3 @@ -54,6 +57,7 @@ jobs: shell: powershell test_golang_oldest: + name: Go tests with previous Go version runs-on: ubuntu-latest # The go verson in this image should be N-1 wrt test_go. container: @@ -65,6 +69,7 @@ jobs: - run: go test ./tsdb/ -test.tsdb-isolation=false test_mixins: + name: Mixins tests runs-on: ubuntu-latest # Whenever the Go version is updated here, .promu.yml # should also be updated. @@ -82,9 +87,10 @@ jobs: - run: git diff --exit-code build: + name: Build Prometheus for common architectures runs-on: ubuntu-latest if: | - !(github.event_name == 'create' && github.event.ref_type != 'tag' && !startsWith(github.event.ref, 'refs/tags/v2.')) + !(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v2.')) && !(github.event_name == 'pull_request' && startsWith(github.event.pull_request.base.ref, 'release-')) && @@ -100,9 +106,10 @@ jobs: parallelism: 3 thread: ${{ matrix.thread }} build_all: + name: Build Prometheus for all architectures runs-on: ubuntu-latest if: | - (github.event_name == 'create' && github.event.ref_type != 'tag' && !startsWith(github.event.ref, 'refs/tags/v2.')) + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v2.')) || (github.event_name == 'pull_request' && startsWith(github.event.pull_request.base.ref, 'release-')) || @@ -119,11 +126,34 @@ jobs: with: parallelism: 12 thread: ${{ matrix.thread }} + golangci: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: '<1.19' + - name: Install snmp_exporter/generator dependencies + run: sudo apt-get update && sudo apt-get -y install libsnmp-dev + if: github.repository == 'prometheus/snmp_exporter' + - name: Lint + uses: golangci/golangci-lint-action@v3.2.0 + with: + version: v1.45.2 + fuzzing: + uses: ./.github/workflows/fuzzing.yml + if: github.event_name == 'pull_request' + codeql: + uses: ./.github/workflows/codeql-analysis.yml publish_main: + name: Publish main branch artefacts runs-on: ubuntu-latest - needs: [test_ui, test_go, test_windows, build_all] - if: "github.event_name == 'push' && github.event.ref == 'refs/heads/main'" + needs: [test_ui, test_go, test_windows, golangci, codeql, build_all] + if: github.event_name == 'push' && github.event.ref == 'refs/heads/main' steps: - uses: actions/checkout@v3 - uses: ./.github/actions/publish_main @@ -133,9 +163,10 @@ jobs: quay_io_login: ${{ secrets.quay_io_login }} quay_io_password: ${{ secrets.quay_io_password }} publish_release: + name: Publish release arfefacts runs-on: ubuntu-latest - needs: [test_ui, test_go, test_windows, build_all] - if: github.event_name == 'create' && github.event.ref_type == 'tag' && startsWith(github.event.ref, 'refs/tags/v2.') + needs: [test_ui, test_go, test_windows, golangci, codeql, build_all] + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v2.') steps: - uses: actions/checkout@v3 - uses: ./.github/actions/publish_release @@ -144,3 +175,38 @@ jobs: docker_hub_password: ${{ secrets.docker_hub_password }} quay_io_login: ${{ secrets.quay_io_login }} quay_io_password: ${{ secrets.quay_io_password }} + publish_ui_release: + name: Publish UI on npm Registry + runs-on: ubuntu-latest + needs: [test_ui, codeql] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install nodejs + uses: actions/setup-node@v3 + with: + node-version-file: "web/ui/.nvmrc" + registry-url: "https://registry.npmjs.org" + - uses: actions/cache@v3.0.8 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Check libraries version + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v2.') + run: ./scripts/ui_release.sh --check-package "$(echo ${{ github.ref_name }}|sed s/v2/v0/)" + - name: build + run: make assets + - name: Copy files before publishing libs + run: ./scripts/ui_release.sh --copy + - name: Publish dry-run libraries + if: "!(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v2.'))" + run: ./scripts/ui_release.sh --publish dry-run + - name: Publish libraries + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v2.') + run: ./scripts/ui_release.sh --publish + env: + # The setup-node action writes an .npmrc file with this env variable + # as the placeholder for the auth token + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 55890343d..a3c3c0074 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -2,10 +2,7 @@ name: "CodeQL" on: - push: - branches: [main, release-*] - pull_request: - branches: [main] + workflow_call: schedule: - cron: "26 14 * * 1" diff --git a/.github/workflows/fuzzing.yml b/.github/workflows/fuzzing.yml index b0fc0a4ee..87c40d310 100644 --- a/.github/workflows/fuzzing.yml +++ b/.github/workflows/fuzzing.yml @@ -1,6 +1,6 @@ name: CIFuzz on: - pull_request: + workflow_call: jobs: Fuzzing: runs-on: ubuntu-latest diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 6034bcbf8..000000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: golangci-lint -on: - push: - paths: - - "go.sum" - - "go.mod" - - "**.go" - - "scripts/errcheck_excludes.txt" - - ".github/workflows/golangci-lint.yml" - - ".golangci.yml" - pull_request: - -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: install Go - uses: actions/setup-go@v2 - with: - go-version: 1.18.x - - name: Install snmp_exporter/generator dependencies - run: sudo apt-get update && sudo apt-get -y install libsnmp-dev - if: github.repository == 'prometheus/snmp_exporter' - - name: Lint - uses: golangci/golangci-lint-action@v3.2.0 - with: - version: v1.45.2 diff --git a/.github/workflows/ui_build_and_release.yml b/.github/workflows/ui_build_and_release.yml deleted file mode 100644 index c7900fca7..000000000 --- a/.github/workflows/ui_build_and_release.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: ui_build_and_release -on: - pull_request: - push: - branches: - - main - tags: - - "v0.[0-9]+.[0-9]+*" -jobs: - release: - name: release - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install nodejs - uses: actions/setup-node@v3 - with: - node-version-file: "web/ui/.nvmrc" - registry-url: "https://registry.npmjs.org" - - uses: actions/cache@v3.0.8 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Check libraries version - ## This step is verifying that the version of each package is matching the tag - if: ${{ github.event_name == 'push' && startsWith(github.ref_name, 'v') }} - run: ./scripts/ui_release.sh --check-package "${{ github.ref_name }}" - - name: build - run: make assets - - name: Copy files before publishing libs - run: ./scripts/ui_release.sh --copy - - name: Publish dry-run libraries - if: ${{ github.event_name == 'pull_request' || github.ref_name == 'main' }} - run: ./scripts/ui_release.sh --publish dry-run - - name: Publish libraries - if: ${{ github.event_name == 'push' && startsWith(github.ref_name, 'v') }} - run: ./scripts/ui_release.sh --publish - env: - # The setup-node action writes an .npmrc file with this env variable - # as the placeholder for the auth token - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}