|
| 1 | +name: Pull Request Preview pipelines Testnet |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + - release/* |
| 8 | + types: [ opened, synchronize, closed ] |
| 9 | + |
| 10 | +env: |
| 11 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 12 | + ENV: "stg" |
| 13 | + APP: "aescan-testnet" |
| 14 | + |
| 15 | +concurrency: aescan_staging_environment-${{ github.ref }} |
| 16 | + |
| 17 | +jobs: |
| 18 | + main: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + name: Staging Pipeline Aescan Frontend Testnet |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v3 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + ref: ${{ github.event.pull_request.head.sha }} |
| 26 | + |
| 27 | + - name: Set up Docker Buildx |
| 28 | + id: buildx |
| 29 | + # Use the action from the master, as we've seen some inconsistencies with @v1 |
| 30 | + # Issue: https://github.com/docker/build-push-action/issues/286 |
| 31 | + uses: docker/setup-buildx-action@master |
| 32 | + # Only worked for us with this option on |
| 33 | + with: |
| 34 | + install: true |
| 35 | + |
| 36 | + - name: Cache Docker layers |
| 37 | + uses: actions/cache@v2 |
| 38 | + with: |
| 39 | + path: /tmp/.buildx-cache |
| 40 | + # Key is named differently to avoid collision |
| 41 | + key: ${{ runner.os }}-${{ env.ENV }}-buildx-${{ github.sha }} |
| 42 | + restore-keys: | |
| 43 | + ${{ runner.os }}-${{ env.ENV }}-buildx |
| 44 | +
|
| 45 | + - name: Log in to dockerhub |
| 46 | + uses: docker/login-action@v1 |
| 47 | + with: |
| 48 | + username: ${{ secrets.DOCKERHUB_USER }} |
| 49 | + password: ${{ secrets.DOCKERHUB_PASS }} |
| 50 | + |
| 51 | + - name: Extract metadata for docker |
| 52 | + if: github.event_name == 'pull_request' && github.event.action == 'opened' || github.event.action == 'synchronize' |
| 53 | + id: meta |
| 54 | + uses: docker/metadata-action@v3 |
| 55 | + with: |
| 56 | + images: aeternity/aescan |
| 57 | + tags: | |
| 58 | + type=ref,event=pr |
| 59 | +
|
| 60 | + - name: Get commit sha on PR Sync |
| 61 | + if: github.event_name == 'pull_request' && github.event.action == 'synchronize' |
| 62 | + id: git-sha |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + echo GIT_SHA=$(git rev-parse --short HEAD) >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + - name: Create dotenv |
| 68 | + run: | |
| 69 | + echo APP_VERSION=$(git describe --tags)-preview >> .env |
| 70 | +
|
| 71 | + - name: Build and push docker image |
| 72 | + if: github.event_name == 'pull_request' && github.event.action == 'opened' || github.event.action == 'synchronize' |
| 73 | + uses: docker/build-push-action@v2 |
| 74 | + with: |
| 75 | + context: . |
| 76 | + file: Dockerfile |
| 77 | + push: true |
| 78 | + build-args: BUILD_MODE=development |
| 79 | + tags: ${{ steps.meta.outputs.tags }} |
| 80 | + labels: ${{ steps.meta.outputs.labels }} |
| 81 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 82 | + # Note the mode=max here |
| 83 | + # More: https://github.com/moby/buildkit#--export-cache-options |
| 84 | + # And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue |
| 85 | + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new |
| 86 | + |
| 87 | + - name: Move cache |
| 88 | + if: github.event_name == 'pull_request' && github.event.action == 'opened' || github.event.action == 'synchronize' |
| 89 | + run: | |
| 90 | + rm -rf /tmp/.buildx-cache |
| 91 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 92 | +
|
| 93 | + - uses: actions/checkout@v2 |
| 94 | + with: |
| 95 | + repository: aeternity/gitops-apps-aelabs.git |
| 96 | + ref: stg |
| 97 | + token: ${{ secrets.BOT_GITHUB_TOKEN }} |
| 98 | + persist-credentials: false |
| 99 | + fetch-depth: 0 |
| 100 | + |
| 101 | + - name: Chekc the initial PR deployment status before make a PR Sync. |
| 102 | + if: github.event_name == 'pull_request' && github.event.action == 'synchronize' |
| 103 | + uses: aeternity/ae-github-actions/deploy-status@v7 |
| 104 | + with: |
| 105 | + url: https://pr-${{ env.PR_NUMBER }}-${{ env.APP }}.${{ env.ENV }}.service.aepps.com |
| 106 | + |
| 107 | + - name: Staging PR Sync |
| 108 | + if: github.event_name == 'pull_request' && github.event.action == 'synchronize' |
| 109 | + uses: aeternity/ae-github-actions/argocd-pr-sync@v5 |
| 110 | + with: |
| 111 | + git-sha: ${{ steps.git-sha.outputs.GIT_SHA }} |
| 112 | + url-prefix: pr-${{ env.PR_NUMBER }} |
| 113 | + env: ${{ env.ENV }} |
| 114 | + app: ${{ env.APP }} |
| 115 | + |
| 116 | + - name: Staging deploy |
| 117 | + if: github.event_name == 'pull_request' && github.event.action == 'opened' |
| 118 | + uses: aeternity/ae-github-actions/argocd-deploy@v5 |
| 119 | + with: |
| 120 | + url-prefix: pr-${{ env.PR_NUMBER }} |
| 121 | + env: ${{ env.ENV }} |
| 122 | + app: ${{ env.APP }} |
| 123 | + |
| 124 | + - name: Staging undeploy |
| 125 | + if: github.event_name == 'pull_request' && github.event.action == 'closed' && startsWith(github.head_ref, 'release') != true |
| 126 | + uses: aeternity/ae-github-actions/argocd-undeploy@v5 |
| 127 | + with: |
| 128 | + url-prefix: pr-${{ env.PR_NUMBER }} |
| 129 | + env: ${{ env.ENV }} |
| 130 | + app: ${{ env.APP }} |
| 131 | + |
| 132 | + - name: Print PR url |
| 133 | + |
| 134 | + if: github.event_name == 'pull_request' && github.event.action == 'opened' |
| 135 | + env: |
| 136 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 137 | + with: |
| 138 | + msg: Deployed to https://pr-${{ env.PR_NUMBER }}-aescan.${{ env.ENV }}.service.aepps.com and https://pr-${{ env.PR_NUMBER }}-aescan-testnet.${{ env.ENV }}.service.aepps.com |
| 139 | + check_for_duplicate_msg: true |
| 140 | + |
| 141 | + - name: Push changes |
| 142 | + uses: ad-m/github-push-action@master |
| 143 | + with: |
| 144 | + repository: aeternity/gitops-apps-aelabs |
| 145 | + github_token: ${{ secrets.BOT_GITHUB_TOKEN }} |
| 146 | + branch: stg |
0 commit comments