|
| 1 | +name: Semantic Release workflow |
| 2 | +run-name: ${{ github.actor }} Semantic Release workflow |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - "main" |
| 8 | + |
| 9 | +env: |
| 10 | + PROJECT_ID: "${{ secrets.PROJECT_ID }}" |
| 11 | + GAR_LOCATION: "${{ secrets.GAR_LOCATION }}" |
| 12 | + SLACK_WEBHOOK_URL: "${{ secrets.SLACK_WEBHOOK_URL}}" |
| 13 | + SLACK_CHANNEL: "${{ secrets.GITHUBACTIONS_SLACK_CHANNEL }}" |
| 14 | + |
| 15 | +jobs: |
| 16 | + semantic: |
| 17 | + permissions: write-all |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + id: checkout |
| 22 | + uses: actions/checkout@v6 |
| 23 | + with: |
| 24 | + token: ${{ secrets.GH_TOKEN }} |
| 25 | + ref: main |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Set up Node.js |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: ${{ env.NODE_VERSION }} |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: npm install |
| 35 | + |
| 36 | + - name: Run Semantic Release |
| 37 | + run: npx semantic-release |
| 38 | + env: |
| 39 | + JIRA_URL: ${{ vars.JIRA_URL }} |
| 40 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
| 41 | + |
| 42 | + - name: Set Git config |
| 43 | + run: | |
| 44 | + git config --local user.email "actions@github.com" |
| 45 | + git config --local user.name "Github Actions" |
| 46 | + |
| 47 | + - name: Fetch latest changes from main |
| 48 | + run: | |
| 49 | + git fetch origin main |
| 50 | + git reset --hard origin/main |
| 51 | + |
| 52 | + - name: Merge changes from main to dev |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
| 55 | + run: | |
| 56 | + git fetch origin dev |
| 57 | + git checkout dev |
| 58 | + git merge --no-ff main || true |
| 59 | + git checkout --theirs . |
| 60 | + git add . |
| 61 | + git commit -m "Auto-resolve merge conflicts by keeping main's changes [skip ci]" || echo "No changes to commit" |
| 62 | + |
| 63 | + git push origin dev |
| 64 | +
|
| 65 | + build: |
| 66 | + needs: semantic |
| 67 | + permissions: |
| 68 | + contents: write |
| 69 | + id-token: write |
| 70 | + |
| 71 | + runs-on: ubuntu-latest |
| 72 | + environment: release |
| 73 | + steps: |
| 74 | + - name: Checkout |
| 75 | + id: checkout |
| 76 | + uses: actions/checkout@v6 |
| 77 | + with: |
| 78 | + ref: main |
| 79 | + |
| 80 | + - name: Read BASE IMAGE VERSION file |
| 81 | + id: getappversion |
| 82 | + run: echo "appversion=$(sed -n 's/^MEDCAT_BASE_IMAGE_VERSION=\(.*\)/\1/p' < medcat_versions.yml)" >> $GITHUB_OUTPUT |
| 83 | + |
| 84 | + - name: Read MEDCAT VERSION |
| 85 | + id: getversion |
| 86 | + run: | |
| 87 | + sed -n 's/^appVersion:\(.*\)/\1/p' < "chart/gateway-medcat/Chart" > "version" |
| 88 | + echo "version=$(sed 's/.*\"\(.*\)\".*/\1/g' "version")" >> "$GITHUB_OUTPUT" |
| 89 | +
|
| 90 | + - name: Google Auth |
| 91 | + id: auth |
| 92 | + uses: "google-github-actions/auth@v4" |
| 93 | + with: |
| 94 | + token_format: "access_token" |
| 95 | + workload_identity_provider: "${{ secrets.WIF_PROVIDER }}" |
| 96 | + service_account: "${{ secrets.WIF_SERVICE_ACCOUNT }}" |
| 97 | + |
| 98 | + - name: "Set up Cloud SDK" |
| 99 | + id: setupsdk |
| 100 | + uses: "google-github-actions/setup-gcloud@v1" |
| 101 | + with: |
| 102 | + version: ">= 363.0.0" |
| 103 | + |
| 104 | + - name: "Use gcloud CLI to download the models from google storage bucket" |
| 105 | + id: copymodel |
| 106 | + run: gsutil -m cp -r '${{ secrets.BUCKET_PATH }}' . |
| 107 | + |
| 108 | + - name: Login to GAR |
| 109 | + id: garlogin |
| 110 | + uses: docker/login-action@v3 |
| 111 | + with: |
| 112 | + registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.PROJECT_ID }} |
| 113 | + username: oauth2accesstoken |
| 114 | + password: ${{ steps.auth.outputs.access_token }} |
| 115 | + |
| 116 | + - name: Build and Push Container |
| 117 | + id: build |
| 118 | + shell: bash |
| 119 | + env: |
| 120 | + GAR_LOCATION: ${{ secrets.GAR_LOCATION }} |
| 121 | + PROJECT_ID: ${{ secrets.PROJECT_ID }} |
| 122 | + GAR_NAME: ${{ secrets.GAR_NAME }} |
| 123 | + |
| 124 | + run: |- |
| 125 | + docker build -t '${{ env.GAR_LOCATION }}'-docker.pkg.dev/'${{ env.PROJECT_ID }}'/'${{ env.GAR_NAME }}'/${{ steps.getversion.outputs.version }}:${{ github.sha }} -t '${{ env.GAR_LOCATION }}'-docker.pkg.dev/'${{ env.PROJECT_ID }}'/'${{ env.GAR_NAME }}'/${{ steps.getversion.outputs.version }}:latest --build-arg MEDCAT_BASE_IMAGE_VERSION=${{ steps.getappversion.outputs.appversion }} ./ |
| 126 | + docker push --all-tags '${{ env.GAR_LOCATION }}'-docker.pkg.dev/'${{ env.PROJECT_ID }}'/'${{ env.GAR_NAME }}'/${{ steps.getversion.outputs.version }} |
| 127 | +
|
| 128 | + - name: Run Notification |
| 129 | + id: runnotificationsent |
| 130 | + uses: act10ns/slack@v1 |
| 131 | + with: |
| 132 | + status: ${{ job.status }} |
| 133 | + steps: ${{ toJson(steps) }} |
| 134 | + channel: ${{ env.SLACK_CHANNEL }} |
| 135 | + message: Running release build on {{ env.GITHUB_REF_NAME }} branch ${{ job.status }} |
| 136 | + if: always() |
0 commit comments