diff --git a/.github/workflows/service_test_ghac.yml b/.github/workflows/service_test_ghac.yml index 0d80cbc03dee..edd911a0983c 100644 --- a/.github/workflows/service_test_ghac.yml +++ b/.github/workflows/service_test_ghac.yml @@ -18,38 +18,34 @@ name: Service Test Ghac on: - push: - branches: - - main - pull_request: - branches: - - main - paths: - - "core/Cargo.toml" - - "core/Cargo.lock" - - "core/core/Cargo.toml" - - "core/core/src/**" - - "core/layers/**" - - "core/testkit/**" - - "core/tests/**" - - "!core/core/src/docs/**" - - "core/services/azblob/**" - - "core/services/azure-common/**" - - "core/services/ghac/**" - - ".github/workflows/service_test_ghac.yml" - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} - cancel-in-progress: true + workflow_call: + inputs: + opendal_repository: + description: "OpenDAL repository to checkout" + required: true + type: string + opendal_ref: + description: "OpenDAL ref to test" + required: true + type: string + correlation_id: + description: "Identifier used by OpenDAL CI to find this run" + required: true + type: string jobs: ghac_v2: + name: ghac v2 runs-on: ubuntu-latest - if: github.event_name == 'push' || !github.event.pull_request.head.repo.fork permissions: actions: write + contents: read steps: - uses: actions/checkout@v6 + with: + repository: ${{ inputs.opendal_repository }} + ref: ${{ inputs.opendal_ref }} + - name: Setup Rust toolchain uses: ./.github/actions/setup with: diff --git a/.github/workflows/service_test_ghac_incoming.yml b/.github/workflows/service_test_ghac_incoming.yml new file mode 100644 index 000000000000..509810620fc3 --- /dev/null +++ b/.github/workflows/service_test_ghac_incoming.yml @@ -0,0 +1,139 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: Service Test Ghac Incoming +# We will replace existing `service_test_ghac_legacy.yml` when we set up +# shared workflows with another repo `opendal-ghac-service-continous-integration` with: +# - this workflow as `service_test_ghac_trigger.yml` +# - and the new definition at `service_test_ghac.yml` + +on: + push: + branches: + - main + pull_request: + branches: + - main + paths: + - "core/Cargo.toml" + - "core/Cargo.lock" + - "core/core/Cargo.toml" + - "core/core/src/**" + - "core/layers/**" + - "core/testkit/**" + - "core/tests/**" + - "!core/core/src/docs/**" + - "core/services/azblob/**" + - "core/services/azure-common/**" + - "core/services/ghac/**" + - ".github/workflows/service_test_ghac_incoming.yml" + - ".github/workflows/service_test_ghac_probe.yml" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + +jobs: + ghac_v2: + runs-on: ubuntu-latest + if: github.event_name == 'push' || !github.event.pull_request.head.repo.fork + timeout-minutes: 90 + permissions: + contents: read + env: + TARGET_WORKFLOW: opendal-ghac-runner.yml + CORRELATION_ID: ghac-${{ github.run_id }}-${{ github.run_attempt }} + OPENDAL_REPOSITORY: ${{ github.repository }} + OPENDAL_REF: ${{ github.event_name == 'pull_request' && format('refs/pull/{0}/merge', github.event.pull_request.number) || github.sha }} + steps: + - uses: actions/checkout@v6 + + - name: Dispatch remote GHAC test + uses: actions/github-script@v8 + with: + # `GITHUB_TOKEN` cannot dispatch workflows in another repository. + # This token must have Actions read/write permission on `opendal-ghac-service-continuous-integration`. + github-token: ${{ secrets.GHAC_SERVICE_CI_TOKEN }} + script: | + const owner = 'apache'; + const repo = 'opendal-ghac-service-continuous-integration'; + const workflow_id = process.env.TARGET_WORKFLOW; + const correlation_id = process.env.CORRELATION_ID; + + await github.rest.actions.createWorkflowDispatch({ + owner, + repo, + workflow_id, + ref: 'ghac-ci', // FIXME: change to `main` upon merge + inputs: { + opendal_repository: process.env.OPENDAL_REPOSITORY, + opendal_ref: process.env.OPENDAL_REF, + correlation_id, + }, + }); + + core.info(`Dispatched ${owner}/${repo}/${workflow_id} with correlation ${correlation_id}`); + + - name: Wait for remote GHAC test + uses: actions/github-script@v8 + with: + github-token: ${{ secrets.GHAC_SERVICE_CI_TOKEN }} + script: | + const { setTimeout } = require('node:timers/promises'); + + const REMOTE_RUN_POLL_ATTEMPTS = 180; // 10s * 180 = 1800s = 30min + const REMOTE_RUN_POLL_INTERVAL_MS = 10000; // 10s + const owner = 'apache'; + const repo = 'opendal-ghac-service-continuous-integration'; + + const workflow_id = process.env.TARGET_WORKFLOW; + const correlation_id = process.env.CORRELATION_ID; + const expectedTitle = `opendal-ghac-${correlation_id}`; + + let run; + for (let attempt = 0; attempt < REMOTE_RUN_POLL_ATTEMPTS; attempt++) { + const { data } = await github.rest.actions.listWorkflowRuns({ + owner, + repo, + workflow_id, + event: 'workflow_dispatch', + per_page: 20, + }); + + run = data.workflow_runs.find(item => item.display_title === expectedTitle); + if (!run) { + core.info(`Waiting for remote run ${expectedTitle} to appear`); + await setTimeout(REMOTE_RUN_POLL_INTERVAL_MS); + continue; + } + + core.info(`Remote run ${run.html_url} is ${run.status}${run.conclusion ? ` / ${run.conclusion}` : ''}`); + if (run.status === 'completed') { + if (run.conclusion !== 'success') { + core.setFailed(`Remote GHAC test failed with conclusion ${run.conclusion}: ${run.html_url}`); + } + return; + } + + await setTimeout(REMOTE_RUN_POLL_INTERVAL_MS); + } + + if (run?.html_url) { + core.setFailed(`Timed out waiting for remote GHAC test: ${run.html_url}`); + } else { + core.setFailed(`Timed out waiting for remote GHAC test ${expectedTitle} to appear`); + } diff --git a/.github/workflows/service_test_ghac_legacy.yml b/.github/workflows/service_test_ghac_legacy.yml new file mode 100644 index 000000000000..0d80cbc03dee --- /dev/null +++ b/.github/workflows/service_test_ghac_legacy.yml @@ -0,0 +1,72 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: Service Test Ghac + +on: + push: + branches: + - main + pull_request: + branches: + - main + paths: + - "core/Cargo.toml" + - "core/Cargo.lock" + - "core/core/Cargo.toml" + - "core/core/src/**" + - "core/layers/**" + - "core/testkit/**" + - "core/tests/**" + - "!core/core/src/docs/**" + - "core/services/azblob/**" + - "core/services/azure-common/**" + - "core/services/ghac/**" + - ".github/workflows/service_test_ghac.yml" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + +jobs: + ghac_v2: + runs-on: ubuntu-latest + if: github.event_name == 'push' || !github.event.pull_request.head.repo.fork + permissions: + actions: write + steps: + - uses: actions/checkout@v6 + - name: Setup Rust toolchain + uses: ./.github/actions/setup + with: + need-nextest: true + + - name: Configure Cache Env + uses: actions/github-script@v8 + with: + script: | + core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + core.exportVariable('ACTIONS_CACHE_SERVICE_V2', 'on'); + + - name: Test + shell: bash + working-directory: core + run: cargo test behavior --features tests,services-ghac + env: + OPENDAL_TEST: ghac + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}