|
| 1 | +name: CI/CD |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "*" |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +env: |
| 11 | + MAIN_PYTHON_VERSION: '3.12' |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + packages: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + code-style: |
| 23 | + name: "Code style checks" |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: "Run PyAnsys code style checks" |
| 27 | + uses: ansys/actions/code-style@v6 |
| 28 | + |
| 29 | + release: |
| 30 | + name: "Release project" |
| 31 | + if: github.event_name == 'push' && contains(github.ref, 'refs/tags') |
| 32 | + needs: [code-style] |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - name: Checkout code |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Release to GitHub |
| 39 | + uses: softprops/action-gh-release@v2 |
| 40 | + with: |
| 41 | + generate_release_notes: true |
| 42 | + |
| 43 | + release-docker: |
| 44 | + name : Generate Docker release |
| 45 | + if: github.event_name == 'push' && contains(github.ref, 'refs/tags') |
| 46 | + needs: [release] |
| 47 | + runs-on: ubuntu-latest |
| 48 | + steps: |
| 49 | + - name: Checkout repository |
| 50 | + uses: actions/checkout@v4 |
| 51 | + |
| 52 | + - name: Set up Docker Buildx |
| 53 | + uses: docker/setup-buildx-action@v3 |
| 54 | + |
| 55 | + - name: Login to GitHub Container Registry |
| 56 | + uses: docker/login-action@v3 |
| 57 | + with: |
| 58 | + registry: ghcr.io |
| 59 | + username: ${{ github.actor }} |
| 60 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + |
| 62 | + - name: Check if tag name contains 'dev' |
| 63 | + run: echo "IS_DEV_TAG=$(echo ${{ github.ref_name }} | grep -q 'dev' && echo 'true' || echo 'false')" >> $GITHUB_ENV |
| 64 | + |
| 65 | + - name: Decompose tag into components |
| 66 | + if: env.IS_DEV_TAG == 'false' |
| 67 | + run: | |
| 68 | + if [[ ${{ github.ref_name }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 69 | + # Split the tag into its components |
| 70 | + IFS='.' read -ra PARTS <<< "${{ github.ref_name }}" |
| 71 | + echo "X=${PARTS[0]}" >> $GITHUB_ENV |
| 72 | + echo "Y=${PARTS[1]}" >> $GITHUB_ENV |
| 73 | + echo "Z=${PARTS[2]}" >> $GITHUB_ENV |
| 74 | + else |
| 75 | + echo "Invalid tag format. Expected vX.Y.Z but got ${{ github.ref_name }}" |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | +
|
| 79 | + - name: Build and push Docker image |
| 80 | + uses: docker/build-push-action@v6 |
| 81 | + if: env.IS_DEV_TAG == 'false' |
| 82 | + with: |
| 83 | + context: . |
| 84 | + file: docker/Dockerfile |
| 85 | + push: true |
| 86 | + platforms: linux/amd64,linux/arm64 |
| 87 | + tags: | |
| 88 | + ghcr.io/${{ github.repository }}:${{ env.X }} , |
| 89 | + ghcr.io/${{ github.repository }}:${{ env.X }}.${{ env.Y }} , |
| 90 | + ghcr.io/${{ github.repository }}:${{ env.X }}.${{ env.Y }}.${{ env.Z }} , |
| 91 | + ghcr.io/${{ github.repository }}:latest |
| 92 | +
|
| 93 | + - name: Build and push Docker image dev |
| 94 | + if: env.IS_DEV_TAG == 'true' |
| 95 | + uses: docker/build-push-action@v6 |
| 96 | + with: |
| 97 | + context: . |
| 98 | + file: docker/Dockerfile |
| 99 | + push: true |
| 100 | + platforms: linux/amd64,linux/arm64 |
| 101 | + tags: | |
| 102 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }} |
| 103 | +
|
| 104 | + main-repo-release: |
| 105 | + name: Update main allie repo and create release |
| 106 | + if: github.event_name == 'push' && contains(github.ref, 'refs/tags') |
| 107 | + needs: [release-docker, release] |
| 108 | + runs-on: ubuntu-latest |
| 109 | + steps: |
| 110 | + - name: Checkout allie repository |
| 111 | + run: | |
| 112 | + git clone --branch main https://${{ secrets.ALLIE_RELEASE_TOKEN }}@github.com/ansys-internal/allie.git |
| 113 | +
|
| 114 | + - name: Setup Go |
| 115 | + uses: actions/setup-go@v5 |
| 116 | + with: |
| 117 | + go-version-file: 'allie/scripts/releasehelper/go.mod' |
| 118 | + |
| 119 | + - name: Run tag script |
| 120 | + run: | |
| 121 | + cd allie/scripts/releasehelper |
| 122 | + go run main.go "tag" ${{ github.ref_name }} ${{ secrets.ALLIE_RELEASE_TOKEN }} |
| 123 | +
|
| 124 | + - name: Commit and push to allie |
| 125 | + run: | |
| 126 | + cd allie |
| 127 | + git config --global user.email '${{ github.actor }}@users.noreply.github.com' |
| 128 | + git config --global user.name '${{ github.actor }}' |
| 129 | + git commit -a -m 'New release triggered by ${{ github.event.repository.name }}' |
| 130 | + git push origin main |
| 131 | +
|
| 132 | + - name: Run release script |
| 133 | + run: | |
| 134 | + cd allie/scripts/releasehelper |
| 135 | + go run main.go "release" ${{ github.ref_name }} ${{ secrets.ALLIE_RELEASE_TOKEN }} |
0 commit comments