👷 Add explicit least privilege permissions for each workflow #927
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ci | |
| on: | |
| push: | |
| branches: | |
| - master | |
| tags: | |
| - "**" | |
| pull_request: | |
| workflow_dispatch: | |
| # least privilege as default, should be overridden per job if necessary | |
| permissions: | |
| contents: read | |
| env: | |
| IMAGE_NAME: maykinmedia/objecttypes-api | |
| jobs: | |
| # determine changed files to decide if certain jobs can be skipped or not | |
| changed-files: | |
| runs-on: ubuntu-latest # windows-latest | macos-latest | |
| name: Determine changed files | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get changed PY files | |
| id: changed-py-files | |
| run: bin/check_changed_files.sh ^src/.*\.py$ | |
| - name: Get changed requirements files | |
| id: changed-requirements | |
| run: bin/check_changed_files.sh ^requirements/.*\.txt$ | |
| outputs: | |
| changed-py-files: ${{ steps.changed-py-files.outputs.any_changed }} | |
| changed-requirements: ${{ steps.changed-requirements.outputs.any_changed }} | |
| tests: | |
| strategy: | |
| matrix: | |
| postgres: ["14", "15", "16", "17"] | |
| use_pooling: [false] | |
| include: | |
| - postgres: "17" | |
| use_pooling: true | |
| name: Run the Django test suite (PG ${{ matrix.postgres }}, ${{matrix.use_pooling && 'with connection pooling' || ''}} | |
| runs-on: ubuntu-latest | |
| needs: | |
| - changed-files | |
| if: ${{ needs.changed-files.outputs.changed-py-files == 'true'|| needs.changed-files.outputs.changed-requirements == 'true'|| github.event_name == 'push' }} | |
| services: | |
| postgres: | |
| image: postgres:${{ matrix.postgres }} | |
| env: | |
| POSTGRES_HOST_AUTH_METHOD: trust | |
| ports: | |
| - 5432:5432 | |
| # needed because the postgres container does not provide a healthcheck | |
| options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up backend environment | |
| uses: maykinmedia/setup-django-backend@v1.3 | |
| with: | |
| python-version: "3.12" | |
| setup-node: true | |
| - name: Run tests | |
| run: | | |
| python src/manage.py collectstatic --noinput --link | |
| coverage run src/manage.py test src | |
| env: | |
| DJANGO_SETTINGS_MODULE: objecttypes.conf.ci | |
| SECRET_KEY: dummy | |
| DB_USER: postgres | |
| DB_PASSWORD: "" | |
| DB_POOL_ENABLED: ${{ matrix.use_pooling }} | |
| - name: Publish coverage report | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| store-reusable-workflow-vars: | |
| name: create values which can be passed through a reusable workflow | |
| runs-on: ubuntu-latest | |
| outputs: | |
| image-name: ${{ steps.image-name.outputs.image-name }} | |
| steps: | |
| - run: echo "image-name=$IMAGE_NAME" >> $GITHUB_OUTPUT | |
| name: "Store the docker image name" | |
| id: image-name | |
| open-api-ci: | |
| uses: maykinmedia/open-api-workflows/.github/workflows/ci.yml@v6 | |
| needs: | |
| - store-reusable-workflow-vars | |
| with: | |
| main-branch: "master" | |
| python-version: "3.12" | |
| docker-image-name: ${{ needs.store-reusable-workflow-vars.outputs.image-name }} | |
| django-settings-module: objecttypes.conf.ci | |
| run-docs: false | |
| open-api-publish: | |
| uses: maykinmedia/open-api-workflows/.github/workflows/publish.yml@v6 | |
| needs: | |
| - store-reusable-workflow-vars | |
| - open-api-ci | |
| - tests | |
| with: | |
| docker-image-name: ${{ needs.store-reusable-workflow-vars.outputs.image-name }} | |
| repository-owner: "maykinmedia" | |
| secrets: | |
| docker-username: ${{ secrets.DOCKER_USERNAME }} | |
| docker-token: ${{ secrets.DOCKER_TOKEN }} |