diff --git a/.github/workflows/_check_code.yaml b/.github/workflows/_check_code.yaml new file mode 100644 index 0000000..765a6a8 --- /dev/null +++ b/.github/workflows/_check_code.yaml @@ -0,0 +1,30 @@ +name: Code checks + +on: + # Runs when manually triggered from the GitHub UI. + workflow_dispatch: + + # Runs when invoked by another workflow. + workflow_call: + +jobs: + actions_lint_check: + name: Actions lint check + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v6 + - name: Run actionlint + uses: rhysd/actionlint@v1.7.9 + + lint_check: + name: Lint check + uses: apify/workflows/.github/workflows/python_lint_check.yaml@main + with: + python-versions: '["3.10", "3.11", "3.12", "3.13", "3.14"]' + + type_check: + name: Type check + uses: apify/workflows/.github/workflows/python_type_check.yaml@main + with: + python-versions: '["3.10", "3.11", "3.12", "3.13", "3.14"]' diff --git a/.github/workflows/_tests.yaml b/.github/workflows/_tests.yaml new file mode 100644 index 0000000..d2093ad --- /dev/null +++ b/.github/workflows/_tests.yaml @@ -0,0 +1,39 @@ +name: Tests + +on: + # Runs when manually triggered from the GitHub UI. + workflow_dispatch: + + # Runs when invoked by another workflow. + workflow_call: + +jobs: + # Create a custom unit tests job, because apify-shared-python doesn't use codecov report. + unit_tests: + name: Unit tests + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python-version }} + + - name: Set up uv package manager + uses: astral-sh/setup-uv@v7 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Python dependencies + run: make install-dev + + - name: Run unit tests + run: make unit-tests-cov diff --git a/.github/workflows/check_pr_title.yaml b/.github/workflows/check_pr_title.yaml deleted file mode 100644 index 73298ca..0000000 --- a/.github/workflows/check_pr_title.yaml +++ /dev/null @@ -1,14 +0,0 @@ -name: Check PR title - -on: - pull_request_target: - types: [opened, edited, synchronize] - -jobs: - check_pr_title: - name: Check PR title - runs-on: ubuntu-latest - steps: - - uses: amannn/action-semantic-pull-request@v5.5.3 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/manual_release_stable.yaml b/.github/workflows/manual_release_stable.yaml new file mode 100644 index 0000000..f5ff240 --- /dev/null +++ b/.github/workflows/manual_release_stable.yaml @@ -0,0 +1,100 @@ +name: Stable release + +on: + # Runs when manually triggered from the GitHub UI, with options to specify the type of release. + workflow_dispatch: + inputs: + release_type: + description: Release type + required: true + type: choice + default: auto + options: + - auto + - custom + - patch + - minor + - major + custom_version: + description: The custom version to bump to (only for "custom" type) + required: false + type: string + default: "" + +concurrency: + group: release + cancel-in-progress: false + +jobs: + code_checks: + name: Code checks + uses: ./.github/workflows/_check_code.yaml + + tests: + name: Tests + uses: ./.github/workflows/_tests.yaml + + release_prepare: + name: Release prepare + needs: [code_checks, tests] + runs-on: ubuntu-latest + outputs: + version_number: ${{ steps.release_prepare.outputs.version_number }} + tag_name: ${{ steps.release_prepare.outputs.tag_name }} + changelog: ${{ steps.release_prepare.outputs.changelog }} + release_notes: ${{ steps.release_prepare.outputs.release_notes }} + steps: + - uses: apify/workflows/git-cliff-release@main + name: Release prepare + id: release_prepare + with: + release_type: ${{ inputs.release_type }} + custom_version: ${{ inputs.custom_version }} + existing_changelog_path: CHANGELOG.md + + changelog_update: + name: Changelog update + needs: [release_prepare] + uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@main + with: + version_number: ${{ needs.release_prepare.outputs.version_number }} + changelog: ${{ needs.release_prepare.outputs.changelog }} + secrets: inherit + + github_release: + name: GitHub release + needs: [release_prepare, changelog_update] + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: GitHub release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ needs.release_prepare.outputs.tag_name }} + name: ${{ needs.release_prepare.outputs.version_number }} + target_commitish: ${{ needs.changelog_update.outputs.changelog_commitish }} + body: ${{ needs.release_prepare.outputs.release_notes }} + + pypi_publish: + name: PyPI publish + needs: [release_prepare, changelog_update] + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write # Required for OIDC authentication. + environment: + name: pypi + url: https://pypi.org/project/apify-shared + steps: + - name: Prepare distribution + uses: apify/workflows/prepare-pypi-distribution@main + with: + package_name: apify-shared + is_prerelease: "" + version_number: ${{ needs.release_prepare.outputs.version_number }} + ref: ${{ needs.changelog_update.outputs.changelog_commitish }} + + # Publishes the package to PyPI using PyPA official GitHub action with OIDC authentication. + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/update_new_issue.yaml b/.github/workflows/on_issue.yaml similarity index 77% rename from .github/workflows/update_new_issue.yaml rename to .github/workflows/on_issue.yaml index 1b65db0..c758a37 100644 --- a/.github/workflows/update_new_issue.yaml +++ b/.github/workflows/on_issue.yaml @@ -1,20 +1,21 @@ -name: Update new issue +name: CI (issue) on: + # Runs when a new issue is opened. issues: types: - opened jobs: label_issues: - name: Label issues + name: Add labels runs-on: ubuntu-latest permissions: issues: write steps: # Add the "t-tooling" label to all new issues - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | github.rest.issues.addLabels({ @@ -22,4 +23,4 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, labels: ["t-tooling"] - }) \ No newline at end of file + }) diff --git a/.github/workflows/on_master.yaml b/.github/workflows/on_master.yaml new file mode 100644 index 0000000..1e87599 --- /dev/null +++ b/.github/workflows/on_master.yaml @@ -0,0 +1,72 @@ +name: CI (master) + +on: + push: + branches: + - master + tags-ignore: + - "**" # Ignore all tags to avoid duplicate executions triggered by tag pushes. + +concurrency: + group: release + cancel-in-progress: false + +jobs: + code_checks: + name: Code checks + uses: ./.github/workflows/_check_code.yaml + + tests: + # Skip this for "ci" and "docs" commits. + if: "!startsWith(github.event.head_commit.message, 'ci') && !startsWith(github.event.head_commit.message, 'docs')" + name: Tests + uses: ./.github/workflows/_tests.yaml + + release_prepare: + # Skip this for "ci", "docs" and "test" commits and for forks. + if: "!startsWith(github.event.head_commit.message, 'ci') && !startsWith(github.event.head_commit.message, 'docs') && !startsWith(github.event.head_commit.message, 'test') && startsWith(github.repository, 'apify/')" + name: Release prepare + needs: [code_checks, tests] + runs-on: ubuntu-latest + outputs: + version_number: ${{ steps.release_prepare.outputs.version_number }} + tag_name: ${{ steps.release_prepare.outputs.tag_name }} + changelog: ${{ steps.release_prepare.outputs.changelog }} + steps: + - uses: apify/workflows/git-cliff-release@main + id: release_prepare + name: Release prepare + with: + release_type: prerelease + existing_changelog_path: CHANGELOG.md + + changelog_update: + name: Changelog update + needs: [release_prepare] + uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@main + with: + version_number: ${{ needs.release_prepare.outputs.version_number }} + changelog: ${{ needs.release_prepare.outputs.changelog }} + secrets: inherit + + pypi_publish: + name: PyPI publish + needs: [release_prepare, changelog_update] + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write # Required for OIDC authentication. + environment: + name: pypi + url: https://pypi.org/project/apify-shared + steps: + - name: Prepare distribution + uses: apify/workflows/prepare-pypi-distribution@main + with: + package_name: apify-shared + is_prerelease: "yes" + version_number: ${{ needs.release_prepare.outputs.version_number }} + ref: ${{ needs.changelog_update.outputs.changelog_commitish }} + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml new file mode 100644 index 0000000..13b0e97 --- /dev/null +++ b/.github/workflows/on_pull_request.yaml @@ -0,0 +1,22 @@ +name: CI (PR) + +on: + # Runs whenever a pull request is opened or updated. + pull_request: + +jobs: + pr_title_check: + name: PR title check + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v6.1.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + code_checks: + name: Code checks + uses: ./.github/workflows/_check_code.yaml + + tests: + name: Tests + uses: ./.github/workflows/_tests.yaml diff --git a/.github/workflows/pre_release.yaml b/.github/workflows/pre_release.yaml deleted file mode 100644 index 2726dfb..0000000 --- a/.github/workflows/pre_release.yaml +++ /dev/null @@ -1,65 +0,0 @@ -name: Create a pre-release - -on: - # Trigger a beta version release (pre-release) on push to the master branch. - push: - branches: - - master - tags-ignore: - - "**" # Ignore all tags to prevent duplicate builds when tags are pushed. - - # Or it can be triggered manually. - workflow_dispatch: - -jobs: - release_metadata: - if: "!startsWith(github.event.head_commit.message, 'docs') && !startsWith(github.event.head_commit.message, 'ci') && startsWith(github.repository, 'apify/')" - name: Prepare release metadata - runs-on: ubuntu-latest - outputs: - version_number: ${{ steps.release_metadata.outputs.version_number }} - tag_name: ${{ steps.release_metadata.outputs.tag_name }} - changelog: ${{ steps.release_metadata.outputs.changelog }} - existing_changelog_path: CHANGELOG.md - steps: - - uses: apify/workflows/git-cliff-release@main - id: release_metadata - name: Prepare release metadata - with: - release_type: prerelease - - run_code_checks: - name: Run code checks - uses: ./.github/workflows/run_code_checks.yaml - - update_changelog: - name: Update changelog - needs: [release_metadata, run_code_checks] - uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@main - with: - version_number: ${{ needs.release_metadata.outputs.version_number }} - changelog: ${{ needs.release_metadata.outputs.changelog }} - secrets: - APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} - - publish_to_pypi: - name: Publish to PyPI - needs: [release_metadata, update_changelog] - runs-on: ubuntu-latest - permissions: - contents: write - id-token: write # Required for OIDC authentication. - environment: - name: pypi - url: https://pypi.org/project/apify-shared - steps: - - name: Prepare distribution - uses: apify/workflows/prepare-pypi-distribution@main - with: - package_name: apify-shared - is_prerelease: "yes" - version_number: ${{ needs.release_metadata.outputs.version_number }} - ref: ${{ needs.update_changelog.outputs.changelog_commitish }} - # Publishes the package to PyPI using PyPA official GitHub action with OIDC authentication. - - name: Publish package to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 91f04ad..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,91 +0,0 @@ -name: Create a release - -on: - # Trigger a stable version release via GitHub's UI, with the ability to specify the type of release. - workflow_dispatch: - inputs: - release_type: - description: Release type - required: true - type: choice - default: auto - options: - - auto - - custom - - patch - - minor - - major - custom_version: - description: The custom version to bump to (only for "custom" type) - required: false - type: string - default: "" - -jobs: - release_metadata: - name: Prepare release metadata - runs-on: ubuntu-latest - outputs: - version_number: ${{ steps.release_metadata.outputs.version_number }} - tag_name: ${{ steps.release_metadata.outputs.tag_name }} - changelog: ${{ steps.release_metadata.outputs.changelog }} - release_notes: ${{ steps.release_metadata.outputs.release_notes }} - steps: - - uses: apify/workflows/git-cliff-release@main - name: Prepare release metadata - id: release_metadata - with: - release_type: ${{ inputs.release_type }} - custom_version: ${{ inputs.custom_version }} - existing_changelog_path: CHANGELOG.md - - run_code_checks: - name: Run code checks - uses: ./.github/workflows/run_code_checks.yaml - - update_changelog: - name: Update changelog - needs: [release_metadata, run_code_checks] - uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@main - with: - version_number: ${{ needs.release_metadata.outputs.version_number }} - changelog: ${{ needs.release_metadata.outputs.changelog }} - secrets: - APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} - - create_github_release: - name: Create github release - needs: [release_metadata, update_changelog] - runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - name: Create release - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ needs.release_metadata.outputs.tag_name }} - name: ${{ needs.release_metadata.outputs.version_number }} - target_commitish: ${{ needs.update_changelog.outputs.changelog_commitish }} - body: ${{ needs.release_metadata.outputs.release_notes }} - - publish_to_pypi: - name: Publish to PyPI - needs: [release_metadata, update_changelog] - runs-on: ubuntu-latest - permissions: - contents: write - id-token: write # Required for OIDC authentication. - environment: - name: pypi - url: https://pypi.org/project/apify-shared - steps: - - name: Prepare distribution - uses: apify/workflows/prepare-pypi-distribution@main - with: - package_name: apify-shared - is_prerelease: "" - version_number: ${{ needs.release_metadata.outputs.version_number }} - ref: ${{ needs.update_changelog.outputs.changelog_commitish }} - # Publishes the package to PyPI using PyPA official GitHub action with OIDC authentication. - - name: Publish package to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/run_code_checks.yaml b/.github/workflows/run_code_checks.yaml deleted file mode 100644 index c70e989..0000000 --- a/.github/workflows/run_code_checks.yaml +++ /dev/null @@ -1,34 +0,0 @@ -name: Run code checks - -on: - # Trigger code checks on opening a new pull request. - # Secrets are only made available to the integration tests job, with a manual approval - # step required for PRs from forks. This prevents their potential exposure. - pull_request: - - # Trigger for pushing to the master branch is handled by the pre-release workflow. - - # It should also be possible to trigger checks manually - workflow_dispatch: - - # Allow this workflow to be invoked as a reusable workflow from other workflows - workflow_call: - -jobs: - lint_check: - name: Lint check - uses: apify/workflows/.github/workflows/python_lint_check.yaml@main - with: - python-versions: '["3.10", "3.11", "3.12", "3.13"]' - - type_check: - name: Type check - uses: apify/workflows/.github/workflows/python_type_check.yaml@main - with: - python-versions: '["3.10", "3.11", "3.12", "3.13"]' - - unit_tests: - name: Unit tests - uses: apify/workflows/.github/workflows/python_unit_tests.yaml@main - with: - python-versions: '["3.10", "3.11", "3.12", "3.13"]'