2525
2626jobs:
2727 build:
28- runs-on: ubuntu-16.04
28+ runs-on: ubuntu-latest
2929 steps:
3030
3131 - uses: actions/checkout@master
3232
33- - uses: azure/container-actions/ docker-login@master
33+ - uses: azure/docker-login@v1
3434 with:
3535 login-server: ${{ secrets.CONTAINER_REGISTRY }}
3636 username: ${{ secrets.REGISTRY_USERNAME }}
@@ -47,30 +47,71 @@ jobs:
4747 cluster-name: ${{ secrets.CLUSTER_NAME }}
4848 resource-group: ${{ secrets.RESOURCE_GROUP }}
4949
50+ - name: Create valid child namespace name
51+ id: generate-child-space-name
52+ run: |
53+ branch=${GITHUB_HEAD_REF::63}
54+ branch=$(echo ${branch//[!0-9a-zA-Z]/-} | tr '[:upper:]' '[:lower:]' | sed -e 's/^-/z/' -e 's/-$/z/')
55+ echo ::set-output name=result::$branch
56+
5057 - name: Create child namespaces and add Dev Spaces labels
5158 run: |
52- if [ -n "$(kubectl get namespace $GITHUB_HEAD_REF --ignore-not-found -o name)" ]; then exit 0; fi
53- kubectl create namespace $GITHUB_HEAD_REF
54- kubectl label namespace $GITHUB_HEAD_REF azds.io/parent-space=${{ secrets.MASTER_SPACE }}
55- kubectl label namespace $GITHUB_HEAD_REF azds.io/space=true
56- kubectl label namespace $GITHUB_HEAD_REF azds.io/pull-request-space=true
59+ if [ -n "$(kubectl get namespace ${{steps.generate-child-space-name.outputs.result}} --ignore-not-found -o name)" ]; then exit 0; fi
60+ kubectl create namespace ${{steps.generate-child-space-name.outputs.result}} \
61+ kubectl label namespace ${{steps.generate-child-space-name.outputs.result}} \
62+ azds.io/parent-space=${{ secrets.MASTER_SPACE }} \
63+ azds.io/space=true \
64+ azds.io/pull-request-space=true
5765
5866 - uses: azure/k8s-actions/k8s-create-secret@master
5967 with:
60- namespace: ${{ github.head_ref }}
68+ namespace: ${{ steps.generate-child-space-name.outputs.result }}
6169 container-registry-url: ${{ secrets.CONTAINER_REGISTRY }}
6270 container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
6371 container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
6472 secret-name: ${{ secrets.IMAGE_PULL_SECRET }}
65-
66- - name: Helm Install PR
73+
74+ - name: Create valid release-name
75+ id: generate-release-name
76+ run: |
77+ release=<RELEASE_NAME>-$GITHUB_HEAD_REF
78+ release=${release::53}
79+ release=$(echo ${release//[!0-9a-zA-Z]/-} | tr '[:upper:]' '[:lower:]' | sed -e 's/^-/z/' -e 's/-$/z/')
80+ echo ::set-output name=result::$release
81+
82+ - name: Install Helm for client
83+ id: install-helm-client
84+ run: |
85+ set -e
86+ clientversion=$(helm version --client --short | cut -d' ' -f2 | cut -d'+' -f1)
87+ serverversion=$(helm version --server --short | cut -d' ' -f2 | cut -d'+' -f1)
88+ if [ ! -n "$serverversion" ]; then
89+ echo "Please install Helm on the server!" 1>&2
90+ exit 1
91+ elif [ "$clientversion" == "$serverversion" ]; then
92+ echo The client and server Helm Versions are equal
93+ echo ::set-output name=helm::helm
94+ else
95+ tmp_dir=$(mktemp -d)
96+ export DESIRED_VERSION=$serverversion HELM_INSTALL_DIR=$tmp_dir
97+ curl https://raw.githubusercontent.com/helm/helm/master/scripts/get > get_helm.sh
98+ chmod 700 get_helm.sh
99+ ./get_helm.sh
100+ echo ::set-output name=helm::$tmp_dir/helm
101+ fi
102+
103+ - name: Helm Upgrade PR
67104 run: |
68- helm upgrade --install --namespace $GITHUB_HEAD_REF <RELEASE_NAME>-$GITHUB_HEAD_REF <PATH_TO_THE_CHARTS_FOR_THAT_SERVICE> \
105+ ${{steps.install-helm-client.outputs.helm}} upgrade \
106+ --install ${{steps.generate-release-name.outputs.result}} <PATH_TO_THE_CHARTS_FOR_THAT_SERVICE> \
107+ --namespace ${{steps.generate-child-space-name.outputs.result}} \
69108 --set image.repository=${{ secrets.CONTAINER_REGISTRY }}/<NAME_OF_THE_SERVICE> \
70109 --set image.tag=$GITHUB_SHA \
71110 --set imagePullSecrets[0].name=${{ secrets.IMAGE_PULL_SECRET }}
72111
73- - uses: azure/dev-spaces/actions/add-review-url@Releases/v1
112+ - uses: azure/dev-spaces/actions/add-review-url@Releases/v2
74113 with:
75114 repo-token: ${{ secrets.GITHUB_TOKEN }}
76- host: ${{ secrets.HOST }}
115+ host: ${{ secrets.HOST }}
116+ child-space: ${{steps.generate-child-space-name.outputs.result}}
117+ protocol: 'http'
0 commit comments