|
| 1 | +name: "Release" |
| 2 | +run-name: "Cut Release ${{ github.event.release.tag_name || github.event.inputs.release-tag}}" |
| 3 | +concurrency: |
| 4 | + group: ${{github.workflow}}-${{github.ref}} |
| 5 | + cancel-in-progress: true |
| 6 | +on: |
| 7 | + release: |
| 8 | + types: [published] |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + release-tag: |
| 12 | + description: "Release tag ([servicename-]v#.#.#[-rc#])" |
| 13 | + required: true |
| 14 | + |
| 15 | +env: |
| 16 | + FULL_TAG: ${{ github.event.release.tag_name || github.event.inputs.release-tag}} |
| 17 | + DOCKER_HUB_PROFILE: amplicalabs |
| 18 | + ALL_SERVICES: '["account", "content-publishing", "content-watcher", "graph"]' |
| 19 | + |
| 20 | +jobs: |
| 21 | + set_variables: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + outputs: |
| 24 | + full_tag: ${{ steps.set_version_tag.outputs.TAG }} |
| 25 | + version_tag: ${{ steps.set_version_tag.outputs.VERSION }} |
| 26 | + service_name: ${{ steps.set_version_tag.outputs.SERVICE }} |
| 27 | + service_matrix: ${{ steps.set_version_tag.outputs.SERVICE_MATRIX }} |
| 28 | + valid_semver: ${{ steps.set_version_tag.outputs.valid }} |
| 29 | + test_run: ${{ steps.set_version_tag.outputs.test_run }} |
| 30 | + steps: |
| 31 | + - name: Extract and Validate Version Tag |
| 32 | + id: set_version_tag |
| 33 | + run: | |
| 34 | + valid=false |
| 35 | + test_run=false |
| 36 | + ENTIRE_TAG_RE="^(([[:alpha:]]+)-)?(.*)$" |
| 37 | + VERSION_TAG_RE="^v[\.]?([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(-[[:alpha:][:digit:]\.]+)*)$" |
| 38 | + TAG="${{ github.event.release.tag_name }}" |
| 39 | + echo "Running with tag: ${TAG}" |
| 40 | + if [[ "$TAG" =~ ${ENTIRE_TAG_RE} ]] ; then |
| 41 | + SERVICE=${BASH_REMATCH[2]} |
| 42 | + VERSION_TAG=${BASH_REMATCH[3]} |
| 43 | + if [[ ${VERSION_TAG} =~ ${VERSION_TAG_RE} ]] ; then |
| 44 | + version=${BASH_REMATCH[1]} |
| 45 | + valid=true |
| 46 | + if [[ ${version} = "0.0.1" ]] ; then |
| 47 | + test_run=true |
| 48 | + fi |
| 49 | +
|
| 50 | + if [[ -z "${SERVICE}" ]] ; then |
| 51 | + SERVICE_MATRIX="${ALL_SERVICES}" |
| 52 | + else |
| 53 | + SERVICE_MATRIX="[\"${SERVICE}\"]" |
| 54 | + fi |
| 55 | +
|
| 56 | + echo "::set-output name=TAG::${TAG}" |
| 57 | + echo "::set-output name=VERSION::${VERSION_TAG}" |
| 58 | + echo "::set-output name=SERVICE::${SERVICE}" |
| 59 | + echo "::set-output name=SERVICE_MATRIX::${SERVICE_MATRIX}" |
| 60 | + echo "::set-output name=valid::${valid}" |
| 61 | + echo "::set-output name=test_run::${test_run}" |
| 62 | + fi |
| 63 | + fi |
| 64 | + if [[ "${valid}" = false ]] |
| 65 | + then |
| 66 | + echo "::set-output name=SERVICE_MATRIX::[]" |
| 67 | + echo "::set-output name=valid::${valid}" |
| 68 | + echo "Release tag '${TAG}' is not valid for deployment." |
| 69 | + echo "ERROR: Entered tag ${TAG} is not valid." |
| 70 | + echo "Please use [service-]v#.#.#[-rc#] format." |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | +
|
| 74 | + checkout: |
| 75 | + name: Check Out Repo |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: set_variables |
| 78 | + steps: |
| 79 | + - name: Check Out Repo |
| 80 | + uses: actions/checkout@v4 |
| 81 | + with: |
| 82 | + ref: ${{ needs.set_variables.outputs.full_tag }} |
| 83 | + |
| 84 | + build-and-publish-container-image: |
| 85 | + name: Build and publish container image |
| 86 | + needs: [checkout, set_variables] |
| 87 | + runs-on: ubuntu-latest |
| 88 | + if: needs.set_variables.outputs.valid_semver == 'true' |
| 89 | + strategy: |
| 90 | + matrix: |
| 91 | + service: ${{ fromJson(needs.set_variables.outputs.service_matrix) }} |
| 92 | + steps: |
| 93 | + - name: Deploy Service |
| 94 | + run: | |
| 95 | + echo "Deploying service: ${{ matrix.service }}" |
| 96 | + - name: Set up tags for cp image |
| 97 | + id: cp-tags |
| 98 | + uses: docker/metadata-action@v5 |
| 99 | + with: |
| 100 | + flavor: | |
| 101 | + latest=auto |
| 102 | + images: | |
| 103 | + ${{env.DOCKER_HUB_PROFILE}}/${{matrix.service}}-service |
| 104 | + tags: | |
| 105 | + type=semver,pattern={{version}},value=${{ needs.set_variables.outputs.version_tag }} |
| 106 | + - name: Set up QEMU |
| 107 | + uses: docker/setup-qemu-action@v3 |
| 108 | + with: |
| 109 | + platforms: | |
| 110 | + linux/amd64 |
| 111 | + - name: Set up Docker Buildx |
| 112 | + uses: docker/setup-buildx-action@v3 |
| 113 | + - name: Login to DockerHub |
| 114 | + uses: docker/login-action@v3 |
| 115 | + with: |
| 116 | + username: ${{secrets.DOCKERHUB_USERNAME_FC}} |
| 117 | + password: ${{secrets.DOCKERHUB_TOKEN_FC}} |
| 118 | + - name: Build and Push account-service-service Image |
| 119 | + uses: docker/build-push-action@v5 |
| 120 | + with: |
| 121 | + context: services/${{ matrix.service }} |
| 122 | + platforms: linux/amd64 |
| 123 | + push: ${{ needs.set_variables.outputs.test_run != 'true'}} |
| 124 | + file: services/account/Dockerfile |
| 125 | + tags: ${{ steps.cp-tags.outputs.tags }} |
0 commit comments