transit_model 0.56.1

Transit data management
Documentation
name: Continuous Integration

on:
  push:
    branches: [master]
  pull_request:
  release:
    types: [published]

env:
  IMAGE_ID: "navitia/transit_model"
  DOCKER_REGISTRY_URL: docker.io

jobs:
  rustfmt:
    name: Rust fmt check
    runs-on: ubuntu-latest
    container: kisiodigital/rust-ci:latest
    steps:
      - uses: actions/checkout@v3
      - name: Format
        run: make format
      - name: Failure Slack notif
        if: failure()
        run: |
          curl -s -X POST -H "Content-Type: application/json" -d '${{ env.SLACK_TEXT }}' ${{ secrets.SLACK_CORE_TOOLS_TEAM_URL }}
        env:
          SLACK_TEXT: '{"attachments":[{
          "pretext": "`transit_model CI` requires your attention",
          "text":" :warning: Rust fmt check failed","color":"#D00000",
          "fields":[{"title":"Action URL","value": "https://github.com${{ github.action_path }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}]}]}'
  clippy:
    name: Clippy check
    runs-on: ubuntu-latest
    container: kisiodigital/rust-ci:latest-proj8.1.0
    steps:
      - uses: actions/checkout@v3
      - name: Lint
        run: make lint
      - name: Failure Slack notif
        if: failure()
        run: |
          curl -s -X POST -H "Content-Type: application/json" -d '${{ env.SLACK_TEXT }}' ${{ secrets.SLACK_CORE_TOOLS_TEAM_URL }}
        env:
          SLACK_TEXT: '{"attachments":[{
          "pretext": "`transit_model CI` requires your attention",
          "text":" :warning: Clippy check failed","color":"#D00000",
          "fields":[{"title":"Action URL","value": "https://github.com${{ github.action_path }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}]}]}'
  audit:
    name: Security audit
    runs-on: ubuntu-latest
    container: kisiodigital/rust-ci:latest-proj8.1.0
    continue-on-error: true
    steps:
      - uses: actions/checkout@v3
      - name: Audit
        run: |
          cargo audit
      - name: Failure Slack notif
        if: failure()
        run: |
          curl -s -X POST -H "Content-Type: application/json" -d '${{ env.SLACK_TEXT }}' ${{ secrets.SLACK_CORE_TOOLS_TEAM_URL }}
        env:
          SLACK_TEXT: '{"attachments":[{
          "pretext": "`transit_model CI` requires your attention",
          "text":" :warning: Security audit failed","color":"#D00000",
          "fields":[{"title":"Action URL","value": "https://github.com${{ github.action_path }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}]}]}'
  tests:
    name: Tests
    runs-on: ubuntu-latest
    container: kisiodigital/rust-ci:latest-proj8.1.0
    steps:
    - name: Checkout repository and submodules
      uses: actions/checkout@v3
      with:
        submodules: recursive # for tests/NeTEx
    - name: Install xmllint
      run: apt update && apt install --yes libxml2-utils
    - name: Run tests with and without features
      run: make test
    - name: Failure Slack notif
      if: failure()
      run: |
        curl -s -X POST -H "Content-Type: application/json" -d '${{ env.SLACK_TEXT }}' ${{ secrets.SLACK_CORE_TOOLS_TEAM_URL }}
      env:
        SLACK_TEXT: '{"attachments":[{
        "pretext": "`transit_model CI` requires your attention",
        "text":" :warning: Tests failed","color":"#D00000",
        "fields":[{"title":"Action URL","value": "https://github.com${{ github.action_path }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}]}]}'
  dockerhub:
    name: Dockerhub publication
    needs: [rustfmt, clippy, audit, tests]
    if: github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/master')
    runs-on: ubuntu-latest
    steps:
      - uses: AutoModality/action-clean@v1
      - uses: actions/checkout@v3
      - name: Build image
        run: |
          docker build . --file Dockerfile --tag $IMAGE_ID
      - name: Tag image
        if: github.event_name == 'release'
        run: |
          VERSION="v$( grep "^version =" Cargo.toml | tr -cd '[:digit:].' )"
          docker tag $IMAGE_ID $IMAGE_ID:$VERSION
      - name: Log into registry
        run: |
          echo "${{ secrets.DOCKER_PASSWORD }}" | docker login $DOCKER_REGISTRY_URL --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin
      - name: Push image
        run: |
          docker image push --all-tags $IMAGE_ID
      - name: Failure Slack notif
        if: failure()
        run: |
          curl -s -X POST -H "Content-Type: application/json" -d '${{ env.SLACK_TEXT }}' ${{ secrets.SLACK_CORE_TOOLS_TEAM_URL }}
        env:
          SLACK_TEXT: '{"attachments":[{
          "pretext": "`transit_model Publish` requires your attention",
          "text":" :warning: Publish failed","color":"#D00000",
          "fields":[{"title":"Action URL","value": "https://github.com${{ github.action_path }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}]}]}'
  cratesio:
    name: Crates.io publication
    needs: [dockerhub]
    if: github.event_name == 'release'
    runs-on: ubuntu-latest
    container: kisiodigital/rust-ci:latest-proj8.1.0
    steps:
    - uses: AutoModality/action-clean@v1
    - uses: actions/checkout@v3
    - name: Cargo login
      uses: actions-rs/cargo@v1
      with:
        command: login
        args: -- ${{ secrets.CARGO_TOKEN }}
    - name: Publish
      uses: actions-rs/cargo@v1
      with:
        command: publish
        args: --all-features
    - name: Failure Slack notif
      if: failure()
      run: |
        curl -s -X POST -H "Content-Type: application/json" -d '${{ env.SLACK_TEXT }}' ${{ secrets.SLACK_CORE_TOOLS_TEAM_URL }}
      env:
        SLACK_TEXT: '{"attachments":[{
        "pretext": "`transit_model Publish` requires your attention",
        "text":" :warning: Publish failed","color":"#D00000",
        "fields":[{"title":"Action URL","value": "https://github.com${{ github.action_path }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}]}]}'