-
Notifications
You must be signed in to change notification settings - Fork 45
141 lines (131 loc) · 5.21 KB
/
publish.yaml
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
name: Publish
on:
workflow_call:
inputs:
artifacts-url:
description: "Artifacts URL"
required: false
type: string
default: ""
is_production:
description: "Whether or not it's a released image"
required: false
type: boolean
default: false
secrets:
ARTIFACTS_USER:
required: true
ARTIFACTS_PASSWORD:
required: true
HARBOR_PROD_PROJECT:
required: true
HARBOR_DEV_PROJECT:
required: true
# Push on development branch = PR merge
push:
branches:
- "development/**"
env:
REGISTRY_HOST: registry.scality.com
IS_STABLE: "false"
IS_LATEST: "false"
jobs:
publish-shell-ui:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# "Compute" the harbor project to use
- name: Set registry project to Prod
if: inputs.is_production
run: echo "REGISTRY_PROJECT=${{ secrets.HARBOR_PROD_PROJECT }}" >> $GITHUB_ENV
- name: Set registry project to Dev
if: "! inputs.is_production"
run: echo "REGISTRY_PROJECT=${{ secrets.HARBOR_DEV_PROJECT }}" >> $GITHUB_ENV
# Retrieve Shell UI image from the build, load it and compute version
- name: Retrieve artifacts url
if: inputs.artifacts-url == ''
uses: scality/action-artifacts@v3
id: artifacts
with:
method: get
workflow-name: Pre-merge
url: https://artifacts.scality.net
user: ${{ secrets.ARTIFACTS_USER }}
password: ${{ secrets.ARTIFACTS_PASSWORD }}
- name: Retrieve shell-ui image from artifacts
run: >
curl --fail -LO -u ${{ secrets.ARTIFACTS_USER }}:${{ secrets.ARTIFACTS_PASSWORD }}
${{ inputs.artifacts-url || steps.artifacts.outputs.link }}/images/shell-ui.tar.gz
- name: Load shell-ui image
run: docker load < shell-ui.tar.gz
- name: Retrieve product.txt from artifacts
run: >
curl --fail -LO -u ${{ secrets.ARTIFACTS_USER }}:${{ secrets.ARTIFACTS_PASSWORD }}
${{ inputs.artifacts-url || steps.artifacts.outputs.link }}/product.txt
- name: Compute shell-ui image version and GIT revision
run: |
source product.txt
echo "SHELL_UI_VERSION=$VERSION" >> $GITHUB_ENV
echo "SHELL_UI_SHORT_VERSION=$SHORT_VERSION" >> $GITHUB_ENV
echo "SHELL_UI_REF=$GIT" >> $GITHUB_ENV
# "Compute" if it's the latest version and if it's a stable one
- name: Set is_latest environment variable
run: |
LATEST_DEV_VERSION=$(
git ls-remote | \
awk -F/ '$3 == "development" { print $4 }' | sort -V | tail -n 1
)
if [ "${{ env.SHELL_UI_SHORT_VERSION }}" = "$LATEST_DEV_VERSION" ]; then
echo "IS_LATEST=true" >> $GITHUB_ENV
else
echo "IS_LATEST=false" >> $GITHUB_ENV
fi
- name: Set is_stable environment variable
# NOTE: It cannot be stable if it's not on production
# We consider stable version, tags with no suffix and we also consider that
# current version we try to publish is already tagged
if: inputs.is_production
run: |
LATEST_STABLE_RELEASE=$(
git ls-remote --tags | \
awk -F/ '$3 ~ /^[0-9]+\.[0-9]+\.[0-9]+$/ { print $3 }' | sort -V | tail -n 1
)
if [ "${{ env.SHELL_UI_VERSION }}" = "$LATEST_STABLE_RELEASE" ]; then
echo "IS_STABLE=true" >> $GITHUB_ENV
else
echo "IS_STABLE=false" >> $GITHUB_ENV
fi
# Tag shell-ui image before upload to registry
# (depending whether or not it's for production)
- name: Tag shell-ui image with current version
run: >
docker tag "shell-ui:v${{ env.SHELL_UI_VERSION }}"
"${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_PROJECT }}/shell-ui:v${{ env.SHELL_UI_VERSION }}"
- name: Tag shell-ui image with commit short revision
# Only tag with commit short version when pushing on dev
if: "! inputs.is_production"
run: >
docker tag "shell-ui:v${{ env.SHELL_UI_VERSION }}"
"${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_PROJECT }}/shell-ui:v${{ env.SHELL_UI_VERSION }}-${{ env.SHELL_UI_REF }}"
- name: Tag shell-ui image as latest
if: fromJSON(env.IS_LATEST)
run: >
docker tag "shell-ui:v${{ env.SHELL_UI_VERSION }}"
"${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_PROJECT }}/shell-ui:latest"
- name: Tag shell-ui image as stable
if: fromJSON(env.IS_STABLE)
run: >
docker tag "shell-ui:v${{ env.SHELL_UI_VERSION }}"
"${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_PROJECT }}/shell-ui:stable"
# Push image to the registry
- name: Login to the registry
run: >
docker login "${{ env.REGISTRY_HOST }}"
--username "${{ secrets.REGISTRY_LOGIN }}" --password "${{ secrets.REGISTRY_PASSWORD }}"
- name: Push shell-ui images to the registry
run: >
docker push --all-tags
"${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_PROJECT }}/shell-ui"