|
| 1 | +name: buildTestPublishContainerDeploy |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + release: |
| 7 | + types: |
| 8 | + - published |
| 9 | + pull_request: |
| 10 | + workflow_dispatch: |
| 11 | +env: |
| 12 | + req2stdoutContainerTag: latest |
| 13 | +jobs: |
| 14 | + publish-container: |
| 15 | + if: ${{ github.repository == 'f-w/req2stdout' && github.event_name != 'pull_request' }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + packages: write |
| 20 | + steps: |
| 21 | + - name: Update req2stdoutContainerTag for tags |
| 22 | + if: ${{ startsWith(github.ref, 'refs/tags/') }} |
| 23 | + run: echo req2stdoutContainerTag=$(echo $GITHUB_REF | cut -d / -f 3 | cut -d v -f 2- | cut -d . -f 1,2) >> $GITHUB_ENV |
| 24 | + - name: Update req2stdoutContainerTag for branches |
| 25 | + if: ${{ startsWith(github.ref, 'refs/heads/') && github.ref != 'refs/heads/main' }} |
| 26 | + run: echo req2stdoutContainerTag=$(echo $GITHUB_REF | cut -d / -f 3) >> $GITHUB_ENV |
| 27 | + - name: Save $req2stdoutContainerTag to file |
| 28 | + run: | |
| 29 | + echo $req2stdoutContainerTag > req2stdoutContainerTag.txt |
| 30 | + - name: Upload req2stdoutContainerTag |
| 31 | + if: ${{ startsWith(github.ref, 'refs/heads/') }} |
| 32 | + uses: actions/upload-artifact@v4 |
| 33 | + with: |
| 34 | + name: req2stdoutContainerTag |
| 35 | + path: req2stdoutContainerTag.txt |
| 36 | + - name: Checkout 🛎️ |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + persist-credentials: false |
| 40 | + - name: Login to GitHub Container Registry |
| 41 | + uses: docker/login-action@v3 |
| 42 | + with: |
| 43 | + registry: ghcr.io |
| 44 | + username: ${{ github.repository_owner }} |
| 45 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + - name: Publish Container 🚀 |
| 47 | + uses: docker/build-push-action@v6 |
| 48 | + with: |
| 49 | + push: true |
| 50 | + tags: ghcr.io/f-w/req2stdout:${{ env.req2stdoutContainerTag }} |
| 51 | + build-args: nodeVersion=${{ vars.NODE_VERSION }} |
| 52 | + deploy: |
| 53 | + if: ${{ github.repository == 'f-w/req2stdout' && github.event_name == 'push' }} |
| 54 | + needs: publish-container |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Checkout 🛎️ |
| 58 | + uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + persist-credentials: false |
| 61 | + - name: Install oc |
| 62 | + uses: redhat-actions/oc-installer@v1 |
| 63 | + - name: Authenticate to OCP4 and set context |
| 64 | + uses: redhat-actions/oc-login@v1 |
| 65 | + with: |
| 66 | + openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }} |
| 67 | + openshift_token: ${{ secrets.OPENSHIFT_API_TOKEN }} |
| 68 | + namespace: ${{ secrets.OPENSHIFT_PROJECT }}-prod |
| 69 | + - name: Download req2stdoutContainerTag |
| 70 | + uses: actions/download-artifact@v4 |
| 71 | + with: |
| 72 | + name: req2stdoutContainerTag |
| 73 | + - name: helm upgrade 🚀 |
| 74 | + run: | |
| 75 | + export req2stdoutContainerTag=`cat req2stdoutContainerTag.txt` |
| 76 | + helm upgrade --set image.tag="$req2stdoutContainerTag" req2stdout helm |
| 77 | + oc rollout restart deployment.apps/req2stdout |
0 commit comments