-
Notifications
You must be signed in to change notification settings - Fork 17
95 lines (81 loc) · 3.8 KB
/
main.yml
File metadata and controls
95 lines (81 loc) · 3.8 KB
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
on:
pull_request:
branches:
- main
push:
branches:
- main
name: Publish
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
env:
AZURE_CONTAINER_REGISTRY_URL: hmctspublic.azurecr.io
NEW_AZURE_CONTAINER_REGISTRY_URL: hmctsprod.azurecr.io
steps:
- uses: actions/checkout@v5
- name: use node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org/ # Needed for auth
cache: "npm"
- name: npm install
run: npm install
- name: Prettier Checks
run: npx prettier -c .
- name: "Az CLI login"
uses: azure/login@v2
with:
client-id: c6a3a50b-762f-4b4f-b7ec-f1d84be20cef # DTS Platform Operations GitHub Actions ACR Publisher 1
tenant-id: 531ff96d-0ae9-462a-8d2d-bec7c0b42082 # HMCTS.NET
allow-no-subscriptions: true
- name: "Get Short Sha Hash"
id: get-short-sha
uses: actions/github-script@v7.1.0
with:
script: |
const shortSha = context.sha.substring(0, 7)
core.setOutput('shortSha', shortSha)
- name: "Get Commit Timestamp"
id: get-timestamp
run: |
TIMESTAMP=$(git log -1 --format='%cI' | sed -e's/[-T:]//g' -e's/+.*$//g')
echo "::set-output name=timestamp::$TIMESTAMP"
###################################################
# HMCTSPROD ACR
###################################################
- name: "ACR Login - hmctsprod"
run: |
az acr login --name hmctsprod
- name: "Build and Push PR image - hmctsprod"
if: startsWith(github.ref, 'refs/pull')
run: |
docker build . -t ${{env.NEW_AZURE_CONTAINER_REGISTRY_URL}}/rpe/slack-help-bot:pr-${{github.event.number}}-${{ steps.get-short-sha.outputs.shortSha }}
docker push ${{env.NEW_AZURE_CONTAINER_REGISTRY_URL}}/rpe/slack-help-bot:pr-${{github.event.number}}-${{ steps.get-short-sha.outputs.shortSha }}
- name: "Build and push prod image - hmctsprod"
if: github.ref == 'refs/heads/main'
run: |
docker build . -t ${{env.NEW_AZURE_CONTAINER_REGISTRY_URL}}/rpe/slack-help-bot:prod-${{ steps.get-short-sha.outputs.shortSha }}-${{ steps.get-timestamp.outputs.timestamp }}
docker push ${{env.NEW_AZURE_CONTAINER_REGISTRY_URL}}/rpe/slack-help-bot:prod-${{ steps.get-short-sha.outputs.shortSha }}-${{ steps.get-timestamp.outputs.timestamp }}
###################################################
# HMCTSPUBLIC ACR - Push
###################################################
- name: "ACR Login - hmctspublic"
uses: azure/docker-login@v2
with:
login-server: ${{ env.AZURE_CONTAINER_REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: "Build and Push PR image - hmctspublic"
if: startsWith(github.ref, 'refs/pull')
run: |
docker build . -t ${{ env.AZURE_CONTAINER_REGISTRY_URL }}/rpe/slack-help-bot:pr-${{github.event.number}}-${{ steps.get-short-sha.outputs.shortSha }}
docker push ${{ env.AZURE_CONTAINER_REGISTRY_URL }}/rpe/slack-help-bot:pr-${{github.event.number}}-${{ steps.get-short-sha.outputs.shortSha }}
- name: "Build and push prod image - hmctspublic"
if: github.ref == 'refs/heads/main'
run: |
docker build . -t ${{ env.AZURE_CONTAINER_REGISTRY_URL }}/rpe/slack-help-bot:prod-${{ steps.get-short-sha.outputs.shortSha }}-${{ steps.get-timestamp.outputs.timestamp }}
docker push ${{ env.AZURE_CONTAINER_REGISTRY_URL }}/rpe/slack-help-bot:prod-${{ steps.get-short-sha.outputs.shortSha }}-${{ steps.get-timestamp.outputs.timestamp }}