forked from CGI-FR/IoT-Hub-Portal
-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (132 loc) · 5.64 KB
/
publish.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# This is a basic workflow to help you get started with Actions
name: Publish
# Controls when the workflow will run
on:
release:
types: [ published ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
registry_name: ghcr.io
image_name: iothub-portal
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
name: Build & Push Solution
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4.1.4
- id: docker-tag
uses: yuya-takeyama/docker-tag-from-github-ref-action@v1
- name: Docker Login to ACR
# You may pin to the exact commit or the version.
uses: docker/login-action@v3.1.0
with:
registry: ${{ env.registry_name }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{ env.registry_name }}/${{ github.repository_owner }}/${{ env.image_name }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
latest=true
- name: Build and push
# You may pin to the exact commit or the version.
uses: docker/build-push-action@v5.3.0
with:
# Build's context is the set of files located in the specified PATH or URL
context: src/
# Push is a shorthand for --output=type=registry
push: true
build-args: |
BUILD_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
GITHUB_RUN_NUMBER=${{ github.run_number }}
tags:
${{ steps.meta.outputs.tags }}
arm_templates:
name: Publish cloud infrastructure templates
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.4
- name: Get semver
id: version
uses: docker/metadata-action@v5
with:
images: |
${{ env.registry_name }}/${{ github.repository_owner }}/${{ env.image_name }}
tags: |
type=semver,pattern={{version}}
- uses: actions/checkout@v4.1.4
with:
path: IoT-Hub-Portal
submodules: recursive
- uses: actions/checkout@v4.1.4
with:
ref: arm/main
path: arm-templates
- name: Generate app token
id: generate_app_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
- name: Copy templates
working-directory: arm-templates
run: |
rm -rf ./templates/
mkdir -p templates/azure/iotedge-lorawan-starterkit
touch ./templates/.gitkeep
cp -r ../IoT-Hub-Portal/templates/* ./templates/
rm -rf ./templates/iotedge-lorawan-starterkit/
cp -r ../IoT-Hub-Portal/templates/iotedge-lorawan-starterkit/TemplateBicep/* ./templates/azure/iotedge-lorawan-starterkit/
sed -r -i 's/..\/iotedge-lorawan-starterkit\/TemplateBicep\/main.bicep/.\/iotedge-lorawan-starterkit\/main.bicep/g' ./templates/azure/portal_with_lorawan_and_starter_kit.bicep
- name: Update IoTHub Portal docker image tag in app_service.bicep
working-directory: arm-templates/templates/azure
run: sed -i 's/ghcr.io\/cgi-fr\/iothub-portal:latest/ghcr.io\/cgi-fr\/iothub-portal:${{ fromJSON(steps.version.outputs.json).labels['org.opencontainers.image.version'] }}/g' app_service.bicep
- name: Update IoTHub Portal docker image tag in awsdeploy.yml
working-directory: arm-templates/templates/aws
run: |
sed -i 's/public.ecr.aws\/cgi-fr\/iothub-portal:latest/public.ecr.aws\/cgi-fr\/iothub-portal:${{ fromJSON(steps.version.outputs.json).labels['org.opencontainers.image.version'] }}/g' awsdeploy.yml
- name: Generate ARM file
working-directory: arm-templates/templates/azure
run: az bicep build --file azuredeploy.bicep --outfile azuredeploy.json
- name: Upload azure templates to release assets
uses: AButler/upload-release-assets@v3.0
with:
files: 'arm-templates/templates/azure/*.json'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload aws templates to release assets
uses: AButler/upload-release-assets@v3.0
with:
files: 'arm-templates/templates/aws/*.yml'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Create PR for template updates
uses: peter-evans/create-pull-request@v6
with:
base: 'arm/main'
branch: 'arm/feature/update-templates'
path: 'arm-templates'
commit-message: 'Update templates from release.'
token: ${{ steps.generate_app_token.outputs.token }}
title: '[ARM Templates] Update templates from release'
labels: |
arm-templates
automated pr
body: |
Automated changes to the Azure templates.