snuyanzin commented on code in PR #77: URL: https://github.com/apache/flink-connector-opensearch/pull/77#discussion_r4050154714
########## .github/workflows/weekly-trigger.yml: ########## @@ -0,0 +1,99 @@ +################################################################################ +# 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. +################################################################################ + +# We need to specify repo related information here since Apache INFRA doesn't differentiate +# between several workflows with the same names while preparing a report for GHA usage +# https://infra-reports.apache.org/#ghactions +name: Weekly Trigger Flink Connector Opensearch +on: + schedule: + - cron: "0 0 * * 0" + workflow_dispatch: + +permissions: read-all + +jobs: + Trigger: + if: github.repository == 'apache/flink-connector-opensearch' + permissions: + actions: write + concurrency: + group: ${{ github.workflow }} + cancel-in-progress: true + runs-on: ubuntu-latest + steps: + - name: "Decide and trigger weekly" + uses: actions/github-script@v9 + with: + script: | + // Branches exercised by the weekly matrix. Keep in sync with weekly.yml. + const branches = ['main', 'v1.2']; + + // Resolve the most recent weekly run to learn when it ran and whether it was green. + const { data: runs } = await github.rest.actions.listWorkflowRuns({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'weekly.yml', + per_page: 1, + }); + const lastRun = runs.workflow_runs[0]; + const lastConclusion = lastRun?.conclusion ?? undefined; + const lastRunAt = lastRun?.created_at ?? undefined; + + async function trigger(reason) { + core.info(`Triggering weekly: ${reason}.`); + await github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'weekly.yml', + ref: context.ref.replace('refs/heads/', ''), + }); + } + + // Manual triggers always run. + if (context.eventName === 'workflow_dispatch') { + await trigger('manual dispatch'); + return; + } + + // No previous run, or last run failed/cancelled: run so failures get retried even without new commits. + if (!lastRun) { + await trigger('no previous weekly run found'); + return; + } + if (lastConclusion !== 'success') { + await trigger(`last weekly run concluded '${lastConclusion ?? 'unknown'}', re-running`); + return; + } + + // Last weekly was green: skip unless any watched branch has new commits since it started (manual runs still work). + for (const branch of branches) { Review Comment: yeah, good catch I splitted into 2 parts: snapshot and fixed versions to mitigate it -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
