From eb68e8cbde7f657cf2f1a93cf0b049db123aab9a Mon Sep 17 00:00:00 2001 From: Jan Buchar Date: Fri, 22 Nov 2024 13:22:25 +0100 Subject: [PATCH] ci: Improve release workflows (#638) - closes #469 - closes #706 --- .github/workflows/build_and_deploy_docs.yaml | 9 +++-- .github/workflows/pre_release.yaml | 35 +++++++++++++------- .github/workflows/release.yaml | 34 +++++++++++++------ .github/workflows/run_code_checks.yaml | 12 ++++++- 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build_and_deploy_docs.yaml b/.github/workflows/build_and_deploy_docs.yaml index 9260b0d1a5..0791121252 100644 --- a/.github/workflows/build_and_deploy_docs.yaml +++ b/.github/workflows/build_and_deploy_docs.yaml @@ -1,10 +1,12 @@ name: Build and deploy docs on: - push: - branches: - - master workflow_dispatch: + workflow_call: + inputs: + ref: + required: true + type: string env: NODE_VERSION: 20 @@ -25,6 +27,7 @@ jobs: uses: actions/checkout@v4 with: token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + ref: ${{ github.event_name == 'workflow_call' && inputs.ref || github.ref }} - name: Set up Node uses: actions/setup-node@v4 diff --git a/.github/workflows/pre_release.yaml b/.github/workflows/pre_release.yaml index 89180cf4e2..bc600eb06c 100644 --- a/.github/workflows/pre_release.yaml +++ b/.github/workflows/pre_release.yaml @@ -8,6 +8,10 @@ on: tags-ignore: - "**" # Ignore all tags to prevent duplicate builds when tags are pushed. +concurrency: + group: release + cancel-in-progress: false + jobs: release_metadata: if: "!startsWith(github.event.head_commit.message, 'docs') && !startsWith(github.event.head_commit.message, 'ci') && startsWith(github.repository, 'apify/')" @@ -24,21 +28,22 @@ jobs: with: release_type: prerelease - lint_check: - name: Lint check - uses: apify/workflows/.github/workflows/python_lint_check.yaml@main - - type_check: - name: Type check - uses: apify/workflows/.github/workflows/python_type_check.yaml@main - - unit_tests: - name: Unit tests - uses: apify/workflows/.github/workflows/python_unit_tests.yaml@main + # If github.ref points to a [ci skip] commit, this workflow won't run. + # Otherwise, these checks will be launched from the `run_code_checks` workflow. + wait_for_checks: + name: Wait for code checks to pass + runs-on: ubuntu-latest + steps: + - uses: lewagon/wait-on-check-action@v1.3.4 + with: + ref: ${{ github.ref }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + check-regexp: "( check| tests)$" + wait-interval: 5 update_changelog: name: Update changelog - needs: [release_metadata, lint_check, type_check, unit_tests] + needs: [release_metadata, wait_for_checks] uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@main with: version_number: ${{ needs.release_metadata.outputs.version_number }} @@ -46,6 +51,12 @@ jobs: secrets: APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + build_and_deploy_docs: + needs: [update_changelog] + uses: ./.github/workflows/build_and_deploy_docs.yaml + with: + ref: ${{ needs.update_changelog.outputs.changelog_commitish }} + publish_to_pypi: name: Publish to PyPI needs: [release_metadata, update_changelog] diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f043bb6b6d..d64a9947a5 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -21,6 +21,10 @@ on: type: string default: "" +concurrency: + group: release + cancel-in-progress: false + jobs: release_metadata: name: Prepare release metadata @@ -38,17 +42,19 @@ jobs: release_type: ${{ inputs.release_type }} custom_version: ${{ inputs.custom_version }} - lint_check: - name: Lint check - uses: apify/workflows/.github/workflows/python_lint_check.yaml@main - - type_check: - name: Type check - uses: apify/workflows/.github/workflows/python_type_check.yaml@main - - unit_tests: - name: Unit tests - uses: apify/workflows/.github/workflows/python_unit_tests.yaml@main + # If github.ref points to a [ci skip] commit, we assume that it was added by the pre_release workflow, + # which doesn't push the commit if code checks don't pass. + # Otherwise, the checks will have been triggered by the `run_code_checks` workflow. + wait_for_checks: + name: Wait for code checks to pass + runs-on: ubuntu-latest + steps: + - uses: lewagon/wait-on-check-action@v1.3.4 + with: + ref: ${{ github.ref }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + check-regexp: "( check| tests)$" + wait-interval: 5 update_changelog: name: Update changelog @@ -60,6 +66,12 @@ jobs: secrets: APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + build_and_deploy_docs: + needs: [update_changelog] + uses: ./.github/workflows/build_and_deploy_docs.yaml + with: + ref: ${{ needs.update_changelog.outputs.changelog_commitish }} + create_github_release: name: Create github release needs: [release_metadata, update_changelog] diff --git a/.github/workflows/run_code_checks.yaml b/.github/workflows/run_code_checks.yaml index 51165105ad..ec017357f5 100644 --- a/.github/workflows/run_code_checks.yaml +++ b/.github/workflows/run_code_checks.yaml @@ -6,6 +6,16 @@ on: # step required for PRs from forks. This prevents their potential exposure. pull_request: + # Pushing to the master branch triggers code checks + push: + branches: + - master + tags-ignore: + - "**" # Ignore all tags to prevent duplicate checks when tags are pushed. + + # It should also be possible to trigger checks manually + workflow_dispatch: + jobs: lint_check: name: Lint check @@ -19,7 +29,7 @@ jobs: name: Unit tests uses: apify/workflows/.github/workflows/python_unit_tests.yaml@main secrets: - httpbin_url: https://janbuchar--httpbin.apify.actor?token=${{ secrets.APIFY_HTTPBIN_TOKEN }} + httpbin_url: ${{ secrets.APIFY_HTTPBIN_TOKEN && format('https://janbuchar--httpbin.apify.actor?token={0}', secrets.APIFY_HTTPBIN_TOKEN) || 'https://httpbin.org'}} docs_check: name: Docs check