forked from microsoft/jumpstart-agora-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (90 loc) · 4.26 KB
/
pos-app-build-production.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Promote-to-production
on:
repository_dispatch:
types:
- Kustomization/config-supermarket-pos-contosopos.contoso-supermarket
permissions:
contents: write
pull-requests: write
jobs:
promote-to-production:
runs-on: ubuntu-latest
if: |
github.event.client_payload.metadata.summary == 'env=canary' && github.event.client_payload.severity == 'info' && contains(github.event.client_payload.message,'Health check passed')
steps:
- name: 'Checkout repository'
uses: actions/checkout@v4
- name: 'Login to ACR'
uses: azure/docker-login@v1
with:
login-server: "${{ secrets.ACR_NAME }}.azurecr.io"
username: ${{ secrets.SPN_CLIENT_ID }}
password: ${{ secrets.SPN_CLIENT_SECRET }}
- name: Get latest Canary Image Tag
id: latestImageTag
env:
ACR_NAME: ${{ secrets.ACR_NAME }}
namespace: "canary"
run: |
az login --service-principal --username ${{ secrets.SPN_CLIENT_ID }} --password=${{ secrets.SPN_CLIENT_SECRET }} --tenant ${{ secrets.SPN_TENANT_ID }}
LATEST_TAG=$(az acr repository show-tags --name $ACR_NAME --repository $namespace/contoso-supermarket/pos --orderby time_desc --top 1 --output tsv)
echo $LATEST_TAG
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: Get latest Production Image Tag
id: prodLatestImageTag
env:
ACR_NAME: ${{ secrets.ACR_NAME }}
namespace: "production"
run: |
az login --service-principal --username ${{ secrets.SPN_CLIENT_ID }} --password=${{ secrets.SPN_CLIENT_SECRET }} --tenant ${{ secrets.SPN_TENANT_ID }}
PROD_LATEST_TAG=$(az acr repository show-tags --name $ACR_NAME --repository $namespace/contoso-supermarket/pos --orderby time_desc --top 1 --output tsv)
echo $PROD_LATEST_TAG
echo "latest_tag=$PROD_LATEST_TAG" >> $GITHUB_OUTPUT
- name: Run integration tests
uses: mscoutermarsh/ascii-art-action@master
env:
latest_tag: ${{ steps.latestImageTag.outputs.latest_tag }}
prod_latest_tag: ${{ steps.prodLatestImageTag.outputs.latest_tag }}
if: ${{ env.latest_tag != 'v1.0' && env.prod_latest_tag != env.latest_tag}}
with:
text: 'Integration tests complete!'
- name: 'Build and push new images'
env:
latest_tag: ${{ steps.latestImageTag.outputs.latest_tag }}
namespace: "production"
prod_latest_tag: ${{ steps.prodLatestImageTag.outputs.latest_tag }}
if: ${{ env.latest_tag != 'v1.0' && env.prod_latest_tag != env.latest_tag}}
run: |
docker build ./contoso_supermarket/developer/pos/src -t "${{ secrets.ACR_NAME }}.azurecr.io/$namespace/contoso-supermarket/pos:$latest_tag"
docker push ${{ secrets.ACR_NAME }}.azurecr.io/$namespace/contoso-supermarket/pos:$latest_tag
- name: 'Checkout production branch'
uses: actions/checkout@v4
env:
latest_tag: ${{ steps.latestImageTag.outputs.latest_tag }}
prod_latest_tag: ${{ steps.prodLatestImageTag.outputs.latest_tag }}
if: ${{ env.latest_tag != 'v1.0' && env.prod_latest_tag != env.latest_tag}}
with:
ref: 'production'
- name: 'Update Image tag on production branch and submit PR'
env:
latest_tag: ${{ steps.latestImageTag.outputs.latest_tag }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
prod_latest_tag: ${{ steps.prodLatestImageTag.outputs.latest_tag }}
if: ${{ env.latest_tag != 'v1.0' && env.prod_latest_tag != env.latest_tag}}
run: |
FILE_PATH=$(find . -name "seattle.yaml")
newLine=" image_tag: $latest_tag"
if [ ! -z "$FILE_PATH" ]; then
sed -i "s/.*image_tag.*/$newLine/" $FILE_PATH
else
echo "seattle.yaml not found"
fi
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
newBranch="update-production-image-tag-${latest_tag}"
git checkout -b $newBranch production
git config pull.rebase false
git add --all
git commit -m "Update Image Tag on production to $latest_tag"
git push --set-upstream origin $newBranch
gh pr create --title "Update production Image Tag to $latest_tag" --body "Update production Image Tag to $latest_tag" --base production