name: Validate Pull Request # You must add gitea secrets and enable actions for repository: # CRATES_TOKEN # DOCKER_USER # DOCKER_PASSWORD # ISSUE_API_RW_TOKEN on: pull_request: types: - opened - edited - reopened - synchronize branches: - master - main jobs: {%- raw %} validate: name: Validate runs-on: ubuntu-latest container: image: git.smetan.ru/infra/ci-cargo:latest credentials: username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASSWORD }} steps: - name: Checkout sources uses: https://github.com/actions/checkout@v4 - name: Set cargo registry run: | cat <<"EOF" | tee ~/.cargo/config.toml [registry] global-credential-providers = ["cargo:token"] EOF - name: Login to cargo registry env: {%- endraw %} CARGO_REGISTRY: git_{{git-owner}} {%- raw %} run: cargo login --registry $CARGO_REGISTRY "Bearer ${{ secrets.CRATES_TOKEN }}" - name: Cargo fmt run: cargo fmt --all --check - name: Cargo clippy run: cargo clippy {%- endraw %} test: {%- raw %} name: Tests runs-on: ubuntu-latest container: image: git.smetan.ru/infra/ci-cargo:latest credentials: username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASSWORD }} {%- endraw %} {%- if use_postgres == true %} services: db: # Docker Hub image image: postgres:15 # Provide the password for postgres env: POSTGRES_DB: test_db POSTGRES_USER: user POSTGRES_PASSWORD: pass # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: # Maps tcp port 5432 on service container to the host - 5432:5432 {%- endif %} steps: {%- raw %} - name: Checkout sources uses: https://github.com/actions/checkout@v4 {% endraw -%} {%- if use_postgres == true -%} - name: Setup .env run: | echo "DATABASE_URL=postgres://user:pass@db:5432/test_db" >> .env {%- endif -%} {%- raw %} - name: Set cargo registry run: | cat <<"EOF" | tee ~/.cargo/config.toml [registry] global-credential-providers = ["cargo:token"] EOF - name: Login to cargo registry env: {%- endraw %} CARGO_REGISTRY: git_{{git-owner}} {%- raw %} run: cargo login --registry $CARGO_REGISTRY "Bearer ${{ secrets.CRATES_TOKEN }}" - name: Run Tests run: | make prepare make test curl --silent -X 'POST' \ '${{ github.api_url }}/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments' \ -H 'accept: application/json' \ -H 'Authorization: token ${{ secrets.ISSUE_API_RW_TOKEN }}' \ -H 'Content-Type: application/json' \ -d "{\"body\":\"# Code Coverage:\n$(cat target/coverage/statistic.md)\"}" {%- endraw %}