Skip to content

Commit

Permalink
Basic repository setup (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdusek authored Jan 15, 2024
1 parent 3cd56e2 commit 421ee8e
Show file tree
Hide file tree
Showing 27 changed files with 1,039 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[Makefile]
indent_style = tab

[{*.yaml, *.yml}]
indent_size = 2
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Documentation codeowner

/docs/*.md @TC-MO
/docs/*.mdx @TC-MO
28 changes: 28 additions & 0 deletions .github/workflows/check_version_availability.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check package version availability

on:
workflow_call:

jobs:
check_version_availability:
name: Check version availability
runs-on: ubuntu-latest
if: (!startsWith(github.event.pull_request.title, 'docs:'))

steps:
# We need to check out the head commit in case of PRs, and the default ref otherwise (during release).
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || '' }}"

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"

- name: Install dependencies
run: make install-dev

- name: Check version availability
run: make check-version-availability
1 change: 1 addition & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
1 change: 1 addition & 0 deletions .github/workflows/integration_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
33 changes: 33 additions & 0 deletions .github/workflows/lint_and_type_checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Lint and type checks

on:
workflow_call:

jobs:
lint_and_type_checks:
name: Lint and type checks
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
# We need to check out the head commit in case of PRs, and the default ref otherwise (during release).
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || '' }}"

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: make install-dev

- name: Run lint
run: make lint

- name: Run type checks
run: make type-check
143 changes: 143 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Check & Release

on:
# Push to master will publish a beta version
push:
branches:
- master
tags-ignore:
- "**"
# A release via GitHub releases will publish a stable version
release:
types: [published]
# Workflow dispatch will publish whatever you choose
workflow_dispatch:
inputs:
release_type:
description: Release type
required: true
type: choice
default: alpha
options:
- alpha
- beta
- final

jobs:
should_release:
name: Check whether to release
if: (!startsWith(github.event.head_commit.message, 'docs:') || github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
steps:
- name: Dummy step
run: true

lint_and_type_checks:
name: Run lint and type_checks
needs: [should_release]
uses: ./.github/workflows/lint_and_type_checks.yaml

unit_tests:
name: Run unit tests
needs: [should_release]
uses: ./.github/workflows/unit_tests.yaml

integration_tests:
name: Run integration tests
needs: [should_release]
uses: ./.github/workflows/integration_tests.yaml
secrets: inherit

publish_to_pypi:
name: Publish to PyPI
needs: [should_release, lint_and_type_checks, unit_tests, integration_tests]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
environment:
name: pypi
url: https://pypi.org/p/apify

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install dependencies
run: make install-dev

- # Determine if this is a prerelease or latest release
name: Determine release type
id: get-release-type
run: |
if [ ${{ github.event_name }} = release ]; then
release_type="final"
elif [ ${{ github.event_name }} = push ]; then
release_type="beta"
elif [ ${{ github.event_name }} = workflow_dispatch ]; then
release_type=${{ github.event.inputs.release_type }}
fi
if [ ${release_type} = final ]; then
docker_image_tag="latest"
elif [ ${release_type} = beta ]; then
docker_image_tag="beta"
else
docker_image_tag=""
fi
echo "release_type=${release_type}" >> $GITHUB_OUTPUT
echo "docker_image_tag=${docker_image_tag}" >> $GITHUB_OUTPUT
- # Check whether the released version is listed in CHANGELOG.md
name: Check whether the released version is listed in the changelog
if: steps.get-release-type.outputs.release_type != 'alpha'
run: make check-changelog-entry

- # Check version consistency and increment pre-release version number for prereleases (must be the last step before build)
name: Bump pre-release version
if: steps.get-release-type.outputs.release_type != 'final'
run: python ./scripts/update_version_for_prerelease.py ${{ steps.get-release-type.outputs.release_type }}

- # Build a source distribution and a python3-only wheel
name: Build distribution files
run: make build

- # Check whether the package description will render correctly on PyPI
name: Check package rendering on PyPI
run: make twine-check

- # Publish package to PyPI using their official GitHub action
name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

- # Tag the current commit with the version tag if this is not made from the release event (releases are tagged with the release process)
name: Tag Version
if: github.event_name != 'release'
run: |
git_tag=v`python ./scripts/print_current_package_version.py`
git tag $git_tag
git push origin $git_tag
- # Upload the build artifacts to the release
name: Upload the build artifacts to release
if: github.event_name == 'release'
run: gh release upload ${{ github.ref_name }} dist/*
env:
GH_TOKEN: ${{ github.token }}

- # Trigger building the Python Docker images in apify/apify-actor-docker repo
name: Trigger Docker image build
run: |
PACKAGE_VERSION=`python ./scripts/print_current_package_version.py`
gh api -X POST "/repos/apify/apify-actor-docker/dispatches" \
-F event_type=build-python-images \
-F client_payload[release_tag]=${{ steps.get-release-type.outputs.docker_image_tag }} \
-F client_payload[apify_version]=$PACKAGE_VERSION
env:
GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
49 changes: 49 additions & 0 deletions .github/workflows/run_checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Code quality checks

on:
pull_request_target:

jobs:
check_version_availability:
name: Check version availability
uses: ./.github/workflows/check_version_availability.yaml

lint_and_type_checks:
name: Run lint and type checks
uses: ./.github/workflows/lint_and_type_checks.yaml

unit_tests:
name: Run unit tests
needs: [lint_and_type_checks]
uses: ./.github/workflows/unit_tests.yaml

# If the PR comes from the main repo, run integration tests directly
integration_tests:
if: github.event.pull_request.head.repo.owner.login == 'apify'
name: Run integration tests
needs: [lint_and_type_checks, unit_tests]
uses: ./.github/workflows/integration_tests.yaml
secrets: inherit

# If the PR comes from a fork,
# we need to approve running the workflow first before allowing it to run,
# so that we can check for any unauthorized access to our secrets.
# We need two workflow jobs for that,
# because jobs calling reusable workflows can't use an environment.
# The first job is a dummy job that just asks for approval to use the `fork-worklows` environment.
integration_tests_fork_approve:
if: github.event.pull_request.head.repo.owner.login != 'apify'
name: Approve integration tests from fork
needs: [lint_and_type_checks, unit_tests]
environment: fork-pr-integration-tests
runs-on: ubuntu-latest
steps:
- name: Dummy step
run: true

# The second job is the actual integration tests job.
integration_tests_fork:
name: Run integration tests from fork
needs: [integration_tests_fork_approve]
uses: ./.github/workflows/integration_tests.yaml
secrets: inherit
32 changes: 32 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Unit tests

on:
workflow_call:

jobs:
unit_tests:
name: Run unit tests
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}

steps:
# We need to check out the head commit in case of PRs,
# and the default ref otherwise (during release).
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || '' }}"

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: make install-dev

- name: Run unit tests
run: make unit-tests
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
__pycache__
.mypy_cache
.pytest_cache
.ruff_cache

.venv
.direnv
.envrc
.python-version

*.egg-info/
*.egg
dist/
build/
.coverage*
htmlcov

.vscode
.idea
.DS_Store

docs/changelog.md
8 changes: 8 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
default: true
line-length:
line_length: 120
MD007:
indent: 4
MD004:
style: dash
no-inline-html: false
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: local
hooks:
- id: lint
name: Lint codebase
entry: make lint
language: system
pass_filenames: false

- id: type-check
name: Type-check codebase
entry: make type-check
language: system
pass_filenames: false

- id: unit-tests
name: Run unit tests
entry: make unit-tests
language: system
pass_filenames: false

- id: check-changelog
name: Check whether current version is mentioned in changelog
entry: make check-changelog-entry
language: system
pass_filenames: false
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## [0.0.1](../../releases/tag/v0.0.1) - Unreleased

...
Loading

0 comments on commit 421ee8e

Please sign in to comment.