|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - 'release/*.*' |
| 6 | + - 'main' |
| 7 | + tags: |
| 8 | + - "v*.*.*" |
| 9 | + pull_request: |
| 10 | + types: [opened, synchronize, reopened, labeled] |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + |
| 18 | + labeler: |
| 19 | + name: "Labels" |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + pull-requests: write |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: "Checkotu project" |
| 26 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 |
| 27 | + |
| 28 | + - name: "Update labels" |
| 29 | + uses: micnncim/action-label-syncer@3abd5ab72fda571e69fffd97bd4e0033dd5f495c # v1.3.0 |
| 30 | + env: |
| 31 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - name: "Label pull-request" |
| 34 | + uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0 |
| 35 | + with: |
| 36 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + check-pr-title: |
| 39 | + name: "Check pull-request title follows conventional commits" |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: labeler |
| 42 | + steps: |
| 43 | + - uses: ansys/actions/check-pr-title@1f1f205361706d22f67c71c29b775222380cd95a # v9.0.6 |
| 44 | + with: |
| 45 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + |
| 47 | + code-style: |
| 48 | + name: "Code style checks" |
| 49 | + runs-on: ubuntu-latest |
| 50 | + needs: check-pr-title |
| 51 | + steps: |
| 52 | + - uses: ansys/actions/code-style@1f1f205361706d22f67c71c29b775222380cd95a # v9.0.6 |
| 53 | + with: |
| 54 | + python-version: ${{ env.MAIN_PYTHON_VERSION }} |
| 55 | + |
| 56 | + docker-style: |
| 57 | + name: "Docker style ${{ matrix.directory }}" |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: check-pr-title |
| 60 | + strategy: |
| 61 | + fail-fast: false |
| 62 | + matrix: |
| 63 | + directory: ['pic.Web', 'pic.ApiService'] |
| 64 | + steps: |
| 65 | + - uses: ansys/actions/[email protected] |
| 66 | + with: |
| 67 | + directory: ${{ matrix.directory }} |
| 68 | + recursive: true |
| 69 | + error-level: 1 |
| 70 | + |
| 71 | + docker-build: |
| 72 | + name: "Build ${{ matrix.directory }}" |
| 73 | + runs-on: ubuntu-latest |
| 74 | + needs: [code-style, docker-style] |
| 75 | + permissions: |
| 76 | + contents: read |
| 77 | + packages: write |
| 78 | + env: |
| 79 | + REGISTRY: ghcr.io |
| 80 | + IMAGE_VERSION: ${{ github.ref_name }} |
| 81 | + steps: |
| 82 | + |
| 83 | + - name: "Checkout project" |
| 84 | + uses: actions/checkout@v4 |
| 85 | + |
| 86 | + - name: "Set environment variables" |
| 87 | + run: | |
| 88 | + echo "CREATED_AT=$(date --rfc-3339=seconds)" >> "$GITHUB_ENV" |
| 89 | + echo "REVISION=$(git rev-parse HEAD)" >> "$GITHUB_ENV" |
| 90 | +
|
| 91 | + # Remove leading 'v' from version tag if it exists |
| 92 | + RAW_VERSION="${GITHUB_REF_NAME}" |
| 93 | + IMAGE_VERSION="${RAW_VERSION#v}" |
| 94 | + echo "IMAGE_VERSION=$IMAGE_VERSION" >> "$GITHUB_ENV" |
| 95 | +
|
| 96 | + - name: "Log in to GitHub Container Registry" |
| 97 | + uses: docker/login-action@v3 |
| 98 | + with: |
| 99 | + registry: ${{ env.REGISTRY }} |
| 100 | + username: ${{ github.actor }} |
| 101 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + |
| 103 | + - name: "Build images with Docker Compose" |
| 104 | + run: | |
| 105 | + docker compose build \ |
| 106 | + --build-arg CREATED_AT="${CREATED_AT}" \ |
| 107 | + --build-arg REVISION="${REVISION}" \ |
| 108 | + --build-arg VERSION="${IMAGE_VERSION}" |
| 109 | +
|
| 110 | + - name: "Tag images" |
| 111 | + if: github.ref_type == 'tag' |
| 112 | + run: | |
| 113 | + docker tag pic/frontend $REGISTRY/${{ github.repository }}:pic-frontend-${IMAGE_VERSION} |
| 114 | + docker tag pic/backend $REGISTRY/${{ github.repository }}:pic-backend-${IMAGE_VERSION} |
| 115 | +
|
| 116 | + - name: "Push images" |
| 117 | + if: github.ref_type == 'tag' |
| 118 | + run: | |
| 119 | + docker push $REGISTRY/${{ github.repository }}:pic-frontend-${IMAGE_VERSION} |
| 120 | + docker push $REGISTRY/${{ github.repository }}:pic-backend-${IMAGE_VERSION} |
0 commit comments