|
| 1 | +name: XP Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + container_registry: |
| 7 | + type: string |
| 8 | + required: false |
| 9 | + default: ghcr.io |
| 10 | + environment: |
| 11 | + type: string |
| 12 | + required: false |
| 13 | + secrets: |
| 14 | + ghcr_token: |
| 15 | + required: true |
| 16 | + |
| 17 | +env: |
| 18 | + ARTIFACT_RETENTION_DAYS: 7 |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-ui: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + defaults: |
| 24 | + run: |
| 25 | + working-directory: ui |
| 26 | + steps: |
| 27 | + - name: Checkout to the target branch |
| 28 | + uses: actions/checkout@v3 |
| 29 | + |
| 30 | + - uses: actions/setup-node@v3 |
| 31 | + with: |
| 32 | + node-version: 14 |
| 33 | + |
| 34 | + - name: Get yarn cache directory path |
| 35 | + id: yarn-cache-dir-path |
| 36 | + run: echo "::set-output name=dir::$(yarn cache dir)" |
| 37 | + |
| 38 | + - name: Cache YARN |
| 39 | + uses: actions/cache@v3 |
| 40 | + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) |
| 41 | + with: |
| 42 | + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} |
| 43 | + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} |
| 44 | + restore-keys: | |
| 45 | + ${{ runner.os }}-yarn- |
| 46 | +
|
| 47 | + - name: Install |
| 48 | + run: yarn install --network-concurrency 1 |
| 49 | + |
| 50 | + - name: Lint code |
| 51 | + run: yarn lint |
| 52 | + |
| 53 | + - name: Build UI |
| 54 | + env: |
| 55 | + NODE_OPTIONS: "--max_old_space_size=4096" |
| 56 | + run: yarn build |
| 57 | + |
| 58 | + - name: Publish Artifact |
| 59 | + uses: actions/upload-artifact@v3 |
| 60 | + with: |
| 61 | + name: xp-ui-dist |
| 62 | + path: ui/build/ |
| 63 | + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} |
| 64 | + |
| 65 | + build-management-service: |
| 66 | + runs-on: ubuntu-latest |
| 67 | + env: |
| 68 | + APP_NAME: xp-management |
| 69 | + needs: |
| 70 | + - build-ui |
| 71 | + outputs: |
| 72 | + api-version: ${{ steps.build-image.outputs.api-version }} |
| 73 | + steps: |
| 74 | + - name: Check out code |
| 75 | + uses: actions/checkout@v2 |
| 76 | + with: |
| 77 | + fetch-depth: 0 |
| 78 | + |
| 79 | + - name: Download UI Dist |
| 80 | + uses: actions/download-artifact@v2 |
| 81 | + with: |
| 82 | + name: xp-ui-dist |
| 83 | + path: ui/build |
| 84 | + |
| 85 | + - name: Download Management Service binary |
| 86 | + uses: actions/download-artifact@v2 |
| 87 | + with: |
| 88 | + name: management-service-binary |
| 89 | + path: management-service/bin/ |
| 90 | + |
| 91 | + - name: Sync vendor directory |
| 92 | + working-directory: management-service |
| 93 | + run: | |
| 94 | + echo "Fetching dependencies..." |
| 95 | + go mod vendor |
| 96 | +
|
| 97 | + - name: Build Docker image |
| 98 | + id: build-image |
| 99 | + run: | |
| 100 | + set -o pipefail |
| 101 | + make BIN_NAME=$APP_NAME build-image | tee output.log |
| 102 | + echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)" |
| 103 | +
|
| 104 | + - name: Save Docker image |
| 105 | + run: | |
| 106 | + docker image save \ |
| 107 | + --output xp-management.${{ steps.build-image.outputs.api-version }}.tar \ |
| 108 | + xp-management:${{ steps.build-image.outputs.api-version }} |
| 109 | +
|
| 110 | + - name: Publish Artifact |
| 111 | + uses: actions/upload-artifact@v3 |
| 112 | + with: |
| 113 | + name: xp-management.${{ steps.build-image.outputs.api-version }}.tar |
| 114 | + path: xp-management.${{ steps.build-image.outputs.api-version }}.tar |
| 115 | + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} |
| 116 | + |
| 117 | + build-treatment-service: |
| 118 | + runs-on: ubuntu-latest |
| 119 | + env: |
| 120 | + APP_NAME: xp-treatment |
| 121 | + outputs: |
| 122 | + api-version: ${{ steps.build-image.outputs.api-version }} |
| 123 | + steps: |
| 124 | + - name: Check out code |
| 125 | + uses: actions/checkout@v2 |
| 126 | + with: |
| 127 | + fetch-depth: 0 |
| 128 | + |
| 129 | + - name: Download Treatment Service binary |
| 130 | + uses: actions/download-artifact@v2 |
| 131 | + with: |
| 132 | + name: treatment-service-binary |
| 133 | + path: treatment-service/bin/ |
| 134 | + |
| 135 | + - name: Build Docker image |
| 136 | + id: build-image |
| 137 | + working-directory: treatment-service |
| 138 | + run: | |
| 139 | + set -o pipefail |
| 140 | + make BIN_NAME=$APP_NAME build-image | tee output.log |
| 141 | + echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)" |
| 142 | +
|
| 143 | + - name: Save Docker image |
| 144 | + run: | |
| 145 | + docker image save \ |
| 146 | + --output xp-treatment.${{ steps.build-image.outputs.api-version }}.tar \ |
| 147 | + xp-treatment:${{ steps.build-image.outputs.api-version }} |
| 148 | +
|
| 149 | + - name: Publish Artifact |
| 150 | + uses: actions/upload-artifact@v3 |
| 151 | + with: |
| 152 | + name: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar |
| 153 | + path: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar |
| 154 | + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} |
| 155 | + |
| 156 | + publish-management-service: |
| 157 | + runs-on: ubuntu-latest |
| 158 | + environment: ${{ inputs.environment }} |
| 159 | + needs: |
| 160 | + - build-management-service |
| 161 | + steps: |
| 162 | + - name: Log in to the Container registry |
| 163 | + uses: docker/login-action@v1 |
| 164 | + with: |
| 165 | + registry: ${{ inputs.container_registry }} |
| 166 | + username: ${{ github.actor }} |
| 167 | + password: ${{ secrets.ghcr_token }} |
| 168 | + |
| 169 | + - name: Download Docker image tar |
| 170 | + uses: actions/download-artifact@v2 |
| 171 | + with: |
| 172 | + name: xp-management.${{ needs.build-management-service.outputs.api-version }}.tar |
| 173 | + |
| 174 | + - name: Publish Docker Image |
| 175 | + env: |
| 176 | + DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }} |
| 177 | + run: | |
| 178 | + docker image load --input xp-management.${{ needs.build-management-service.outputs.api-version }}.tar |
| 179 | + docker tag \ |
| 180 | + xp-management:${{ needs.build-management-service.outputs.api-version }} \ |
| 181 | + ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ needs.build-management-service.outputs.api-version }} |
| 182 | + docker push ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ needs.build-management-service.outputs.api-version }} |
| 183 | + |
| 184 | + publish-treatment-service: |
| 185 | + runs-on: ubuntu-latest |
| 186 | + environment: ${{ inputs.environment }} |
| 187 | + needs: |
| 188 | + - build-treatment-service |
| 189 | + steps: |
| 190 | + - name: Log in to the Container registry |
| 191 | + uses: docker/login-action@v1 |
| 192 | + with: |
| 193 | + registry: ${{ inputs.container_registry }} |
| 194 | + username: ${{ github.actor }} |
| 195 | + password: ${{ secrets.ghcr_token }} |
| 196 | + |
| 197 | + - name: Download Docker image tar |
| 198 | + uses: actions/download-artifact@v2 |
| 199 | + with: |
| 200 | + name: xp-treatment.${{ needs.build-treatment-service.outputs.api-version }}.tar |
| 201 | + |
| 202 | + - name: Publish Docker Image |
| 203 | + env: |
| 204 | + DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }} |
| 205 | + run: | |
| 206 | + docker image load --input xp-treatment.${{ needs.build-treatment-service.outputs.api-version }}.tar |
| 207 | + docker tag \ |
| 208 | + xp-treatment:${{ needs.build-treatment-service.outputs.api-version }} \ |
| 209 | + ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ needs.build-treatment-service.outputs.api-version }} |
| 210 | + docker push ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ needs.build-treatment-service.outputs.api-version }} |
0 commit comments