|
| 1 | +name: Auto Preview |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + |
| 7 | +jobs: |
| 8 | + deploy: |
| 9 | + if: github.event.action != 'closed' |
| 10 | + timeout-minutes: 20 |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v2 |
| 15 | + |
| 16 | + - uses: Azure/docker-login@v1 |
| 17 | + with: |
| 18 | + login-server: api7registry.azurecr.io |
| 19 | + username: ${{ secrets.AZURE_REGISTRY_USERNAME }} |
| 20 | + password: ${{ secrets.AZURE_REGISTRY_PASSWORD }} |
| 21 | + |
| 22 | + - id: set-deploy-comment-body |
| 23 | + name: Set deploy comment body |
| 24 | + run: | |
| 25 | + DATE=$(date) |
| 26 | +
|
| 27 | + echo "**The auto preview on your projects!**." >> deploy.txt |
| 28 | + echo "| Name | Status | Preview | Updated|" >> deploy.txt |
| 29 | + echo "| :--- | :----- | :------ | :------ |" >> deploy.txt |
| 30 | + echo "| **contributor-graph** | Deploying | | $DATE |" >> deploy.txt |
| 31 | +
|
| 32 | + BODY=$(cat deploy.txt) |
| 33 | + BODY="${BODY//'%'/'%25'}" |
| 34 | + BODY="${BODY//$'\n'/'%0A'}" |
| 35 | + BODY="${BODY//$'\r'/'%0D'}" |
| 36 | +
|
| 37 | + echo "::set-output name=body::$BODY" |
| 38 | +
|
| 39 | + - name: Find comment |
| 40 | + uses: peter-evans/find-comment@v2 |
| 41 | + id: fc |
| 42 | + with: |
| 43 | + issue-number: ${{ github.event.pull_request.number }} |
| 44 | + body-includes: "The auto preview on your projects!" |
| 45 | + |
| 46 | + - name: Create comment |
| 47 | + if: steps.fc.outputs.comment-id == '' |
| 48 | + uses: peter-evans/create-or-update-comment@v2 |
| 49 | + with: |
| 50 | + issue-number: ${{ github.event.pull_request.number }} |
| 51 | + body: ${{ steps.set-deploy-comment-body.outputs.body }} |
| 52 | + |
| 53 | + - name: Update comment |
| 54 | + if: steps.fc.outputs.comment-id != '' |
| 55 | + uses: peter-evans/create-or-update-comment@v2 |
| 56 | + with: |
| 57 | + edit-mode: replace |
| 58 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 59 | + body: ${{ steps.set-deploy-comment-body.outputs.body }} |
| 60 | + |
| 61 | + - name: Build Contributor Graph Images |
| 62 | + run: | |
| 63 | + docker build -t api7/contributor-graph:dev . |
| 64 | +
|
| 65 | + - name: Push to Azure Registry |
| 66 | + run: | |
| 67 | + docker tag api7/contributor-graph:dev api7registry.azurecr.io/contributor-graph:${{ github.event.pull_request.number }} |
| 68 | + docker push api7registry.azurecr.io/contributor-graph:${{ github.event.pull_request.number }} |
| 69 | +
|
| 70 | + - uses: azure/login@v1 |
| 71 | + with: |
| 72 | + environment: AzureCloud |
| 73 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 74 | + |
| 75 | + - name: Install Contributor Graph |
| 76 | + run: | |
| 77 | + az account set --subscription ffb9d49d-93e7-4f61-bf47-1e9b5f9e4cc0 |
| 78 | + az aks get-credentials --resource-group API7-Web-Preview_group --name API7-Web-Preview |
| 79 | +
|
| 80 | + export ID=${{ github.event.pull_request.number }} |
| 81 | + sh ./preview/install.sh |
| 82 | + kubectl rollout restart deployment/contributor-graph-${{ github.event.pull_request.number }} -n contributor-graph |
| 83 | +
|
| 84 | + - id: set-preview-comment-body |
| 85 | + name: Set preview comment body |
| 86 | + run: | |
| 87 | + DATE=$(date) |
| 88 | +
|
| 89 | + echo "**The auto preview on your projects!**." >> preview.txt |
| 90 | + echo "| Name | Status | Preview | Updated|" >> preview.txt |
| 91 | + echo "| :--- | :----- | :------ | :------ |" >> preview.txt |
| 92 | + echo "| **contributor-graph** | ✅ Ready | [Visit Preview](http://contributor-graph-${{ github.event.pull_request.number }}.preview.api7.ai) | $DATE |" >> preview.txt |
| 93 | +
|
| 94 | + BODY=$(cat preview.txt) |
| 95 | + BODY="${BODY//'%'/'%25'}" |
| 96 | + BODY="${BODY//$'\n'/'%0A'}" |
| 97 | + BODY="${BODY//$'\r'/'%0D'}" |
| 98 | +
|
| 99 | + echo "::set-output name=body::$BODY" |
| 100 | +
|
| 101 | + - name: Find comment |
| 102 | + uses: peter-evans/find-comment@v2 |
| 103 | + id: fc2 |
| 104 | + with: |
| 105 | + issue-number: ${{ github.event.pull_request.number }} |
| 106 | + body-includes: "The auto preview on your projects!" |
| 107 | + |
| 108 | + - name: Update comment |
| 109 | + if: steps.fc2.outputs.comment-id != '' |
| 110 | + uses: peter-evans/create-or-update-comment@v2 |
| 111 | + with: |
| 112 | + comment-id: ${{ steps.fc2.outputs.comment-id }} |
| 113 | + edit-mode: replace |
| 114 | + body: ${{ steps.set-preview-comment-body.outputs.body }} |
| 115 | + |
| 116 | + clean: |
| 117 | + if: github.event.action == 'closed' |
| 118 | + timeout-minutes: 15 |
| 119 | + runs-on: ubuntu-latest |
| 120 | + |
| 121 | + steps: |
| 122 | + - uses: actions/checkout@v2 |
| 123 | + |
| 124 | + - uses: azure/login@v1 |
| 125 | + with: |
| 126 | + environment: AzureCloud |
| 127 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 128 | + |
| 129 | + - name: Uninstall Contributor Graph |
| 130 | + run: | |
| 131 | + az account set --subscription ffb9d49d-93e7-4f61-bf47-1e9b5f9e4cc0 |
| 132 | + az aks get-credentials --resource-group API7-Web-Preview_group --name API7-Web-Preview |
| 133 | +
|
| 134 | + export ID=${{ github.event.pull_request.number }} |
| 135 | + sh ./preview/uninstall.sh |
| 136 | +
|
| 137 | +
|
0 commit comments