Skip to content

fix(workflow): run only when tagging (#6) #25

fix(workflow): run only when tagging (#6)

fix(workflow): run only when tagging (#6) #25

Workflow file for this run

name: CI
on:
push:
branches:
- 'main'
tags:
- "v*.*.*"
pull_request:
types: [opened, synchronize, reopened, labeled]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
labeler:
name: "Labels"
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: "Checkotu project"
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
- name: "Update labels"
uses: micnncim/action-label-syncer@3abd5ab72fda571e69fffd97bd4e0033dd5f495c # v1.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Label pull-request"
uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
check-pr-title:
name: "Check pull-request title follows conventional commits"
runs-on: ubuntu-latest
needs: labeler
steps:
- uses: ansys/actions/check-pr-title@1f1f205361706d22f67c71c29b775222380cd95a # v9.0.6
with:
token: ${{ secrets.GITHUB_TOKEN }}
code-style:
name: "Code style checks"
runs-on: ubuntu-latest
needs: check-pr-title
steps:
- uses: ansys/actions/code-style@1f1f205361706d22f67c71c29b775222380cd95a # v9.0.6
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
docker-style:
name: "Docker style ${{ matrix.directory }}"
runs-on: ubuntu-latest
needs: check-pr-title
strategy:
fail-fast: false
matrix:
directory: ['pic.Web', 'pic.ApiService']
steps:
- uses: ansys/actions/docker-style@v9.0
with:
directory: ${{ matrix.directory }}
recursive: true
error-level: 1
docker-build:
name: "Build ${{ matrix.directory }}"
runs-on: ubuntu-latest
needs: [code-style, docker-style]
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_VERSION: ${{ github.ref_name }}
steps:
- name: "Checkout project"
uses: actions/checkout@v4
- name: "Set environment variables"
run: |
echo "CREATED_AT=$(date --rfc-3339=seconds)" >> "$GITHUB_ENV"
echo "REVISION=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
# Remove leading 'v' from version tag if it exists
RAW_VERSION="${GITHUB_REF_NAME}"
IMAGE_VERSION="${RAW_VERSION#v}"
echo "IMAGE_VERSION=$IMAGE_VERSION" >> "$GITHUB_ENV"
- name: "Log in to GitHub Container Registry"
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Build images with Docker Compose"
run: |
docker compose build \
--build-arg CREATED_AT="${CREATED_AT}" \
--build-arg REVISION="${REVISION}" \
--build-arg VERSION="${IMAGE_VERSION}"
- name: "Tag images"
if: github.ref_type == 'tag'
run: |
docker tag pic/frontend $REGISTRY/${{ github.repository }}:pic-frontend-${IMAGE_VERSION}
docker tag pic/backend $REGISTRY/${{ github.repository }}:pic-backend-${IMAGE_VERSION}
- name: "Push images"
if: github.ref_type == 'tag'
run: |
docker push $REGISTRY/${{ github.repository }}:pic-frontend-${IMAGE_VERSION}
docker push $REGISTRY/${{ github.repository }}:pic-backend-${IMAGE_VERSION}