diff options
author | 2022-01-10 21:58:37 +0200 | |
---|---|---|
committer | 2022-01-10 21:58:37 +0200 | |
commit | 75387ee1556888d2060063c1cc739324a55d4033 (patch) | |
tree | e941fb86fa70ca27d0993ea8fbd02f825df26356 | |
parent | Merge pull request #4 from python-discord/status-embed-flow (diff) | |
parent | Add missing if statement to status embed workflow (diff) |
Merge pull request #5 from python-discord/vendor-ansible-lint
Ansible-lint in pre-commit and dep caching in workflows
-rw-r--r-- | .github/workflows/lint.yml | 56 | ||||
-rw-r--r-- | .github/workflows/status_embed.yaml | 3 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .pre-commit-config.yaml | 20 | ||||
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | requirements.txt | 3 |
6 files changed, 85 insertions, 7 deletions
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 49b05fc..6112699 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,17 +14,61 @@ on: jobs: lint: runs-on: ubuntu-latest + env: + PIP_NO_CACHE_DIR: false + PIP_USER: 1 + PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base + PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache steps: + - name: Add custom PYTHONUSERBASE to PATH + run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH + - uses: actions/checkout@v2 - - name: Lint Ansible playbooks - uses: ansible/ansible-lint-action@master + - name: Setup python + id: python + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + # This step caches our Python dependencies. To make sure we + # only restore a cache when the dependencies, the python version, + # the runner operating system, and the dependency location haven't + # changed, we create a cache key that is a composite of those states. + # + # Only when the context is exactly the same, we will restore the cache. + - name: Python Dependency Caching + uses: actions/cache@v2 + id: python_cache with: - targets: | - playbook.yml - override-deps: | - ansible-lint==5.3.2 + path: ${{ env.PYTHONUSERBASE }} + key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\ + ${{ steps.python.outputs.python-version }}-\ + ${{ hashFiles('./requirements.txt') }}" + + # Install our dependencies if we did not restore a dependency cache + - name: Install dependencies using poetry + if: steps.python_cache.outputs.cache-hit != 'true' + run: | + pip install -U pip wheel setuptools + pip install -r requirements.txt + + # This step caches our pre-commit environment. To make sure we + # do create a new environment when our pre-commit setup changes, + # we create a cache key based on relevant factors. + - name: Pre-commit Environment Caching + uses: actions/cache@v2 + with: + path: ${{ env.PRE_COMMIT_HOME }} + key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\ + ${{ steps.python.outputs.python-version }}-\ + ${{ hashFiles('./.pre-commit-config.yaml') }}" + + # As pre-commit does not support user installs, we set + # PIP_USER=0 to not do a user install. + - name: Run pre-commit hooks + run: export PIP_USER=0; pre-commit run --all-files # Prepare the Pull Request Payload artifact. If this fails, we # we fail silently using the `continue-on-error` option. It's diff --git a/.github/workflows/status_embed.yaml b/.github/workflows/status_embed.yaml index 19b492f..f327865 100644 --- a/.github/workflows/status_embed.yaml +++ b/.github/workflows/status_embed.yaml @@ -17,11 +17,12 @@ jobs: # - Always after the `Lint` workflow, as it runs at the end of our workflow sequence regardless of status. # - Always for the `pull_request` event, as it only runs one workflow. # - Always run for non-success workflows, as they terminate the workflow sequence. + if: >- (github.event.workflow_run.name == 'Lint' && github.event.workflow_run.conclusion != 'skipped') || github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.conclusion == 'failure' || github.event.workflow_run.conclusion == 'cancelled' - name: Send Status Embed to Discord + name: Send Status Embed to Discord runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f316f3b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.5.0 + hooks: + - id: check-merge-conflict + - id: check-toml + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] + - repo: local + hooks: + - id: ansible-lint + name: ansible-lint + description: This hook runs ansible-lint within our project's environment. + entry: ansible-lint + language: system + pass_filenames: false + always_run: true + require_serial: true @@ -1,2 +1,11 @@ # infra Infrastructure for Python Discord + +# Local dev setup +1. Create a virtual environment `python -m venv venv` +1. Activate the virtual environment + - Windows `.\venv\Scripts\activate` + - Linux `source venv/bin/activate` +1. Update pip and builder deps `python -m pip install --upgrade pip wheel setuptools` +1. Install project dependancies `python -m pip install -r requirements.txt` +1. Install the pre-commit hook `pre-commit install` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4112fa7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +ansible +ansible-lint[yamllint] +pre-commit |