Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit d4e9c8d

Browse files
authored
Merge pull request #204 from Azure/s-tuli/childnamespaceUpdate
Update bikes.yml by adding a new step that updates the user's branch …
2 parents 04b73e2 + a4c4087 commit d4e9c8d

File tree

5 files changed

+71
-24
lines changed

5 files changed

+71
-24
lines changed

.github/workflows/bikes.yml

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ on:
1010
jobs:
1111
build:
1212
runs-on: ubuntu-latest
13-
steps:
14-
15-
- uses: actions/checkout@master
16-
17-
- uses: azure/docker-login@releases/v1
13+
steps:
14+
- uses: actions/checkout@master
15+
16+
- uses: azure/docker-login@v1
1817
with:
1918
login-server: ${{ secrets.CONTAINER_REGISTRY }}
2019
username: ${{ secrets.REGISTRY_USERNAME }}
@@ -29,32 +28,72 @@ jobs:
2928
creds: '${{ secrets.AZURE_CREDENTIALS }}'
3029
cluster-name: ${{ secrets.CLUSTER_NAME }}
3130
resource-group: ${{ secrets.RESOURCE_GROUP }}
32-
31+
32+
- name: Create valid child namespace name
33+
id: generate-child-space-name
34+
run: |
35+
branch=${GITHUB_HEAD_REF::63}
36+
branch=$(echo ${branch//[!0-9a-zA-Z]/-} | tr '[:upper:]' '[:lower:]' | sed -e 's/^-/z/' -e 's/-$/z/')
37+
echo ::set-output name=result::$branch
38+
3339
- name: Create child namespaces and add Dev Spaces labels
3440
run: |
35-
if [ -n "$(kubectl get namespace $GITHUB_HEAD_REF --ignore-not-found -o name)" ]; then exit 0; fi
36-
kubectl create namespace $GITHUB_HEAD_REF
37-
kubectl label namespace $GITHUB_HEAD_REF azds.io/parent-space=${{ secrets.MASTER_SPACE }}
38-
kubectl label namespace $GITHUB_HEAD_REF azds.io/space=true
39-
kubectl label namespace $GITHUB_HEAD_REF azds.io/pull-request-space=true
41+
if [ -n "$(kubectl get namespace ${{steps.generate-child-space-name.outputs.result}} --ignore-not-found -o name)" ]; then exit 0; fi
42+
kubectl create namespace ${{steps.generate-child-space-name.outputs.result}} \
43+
kubectl label namespace ${{steps.generate-child-space-name.outputs.result}} \
44+
azds.io/parent-space=${{ secrets.MASTER_SPACE }} \
45+
azds.io/space=true \
46+
azds.io/pull-request-space=true
4047
4148
- uses: azure/k8s-actions/k8s-create-secret@master
4249
with:
43-
namespace: ${{ github.head_ref }}
50+
namespace: ${{ steps.generate-child-space-name.outputs.result }}
4451
container-registry-url: ${{ secrets.CONTAINER_REGISTRY }}
4552
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
4653
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
4754
secret-name: ${{ secrets.IMAGE_PULL_SECRET }}
48-
49-
- name: Helm Install PR
55+
56+
- name: Create valid release-name
57+
id: generate-release-name
5058
run: |
51-
helm init --upgrade --wait
52-
helm upgrade --install --namespace $GITHUB_HEAD_REF bikesharing-$GITHUB_HEAD_REF samples/BikeSharingApp/Bikes/charts/bikes \
59+
release=bikesharing-$GITHUB_HEAD_REF
60+
release=${release::53}
61+
release=$(echo ${release//[!0-9a-zA-Z]/-} | tr '[:upper:]' '[:lower:]' | sed -e 's/^-/z/' -e 's/-$/z/')
62+
echo ::set-output name=result::$release
63+
64+
- name: Install Helm for client
65+
id: install-helm-client
66+
run: |
67+
set -e
68+
clientversion=$(helm version --client --short | cut -d' ' -f2 | cut -d'+' -f1)
69+
serverversion=$(helm version --server --short | cut -d' ' -f2 | cut -d'+' -f1)
70+
if [ ! -n "$serverversion" ]; then
71+
echo "Please install Helm on the server!" 1>&2
72+
exit 1
73+
elif [ "$clientversion" == "$serverversion" ]; then
74+
echo The client and server Helm Versions are equal
75+
echo ::set-output name=helm::helm
76+
else
77+
tmp_dir=$(mktemp -d)
78+
export DESIRED_VERSION=$serverversion HELM_INSTALL_DIR=$tmp_dir
79+
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get > get_helm.sh
80+
chmod 700 get_helm.sh
81+
./get_helm.sh
82+
echo ::set-output name=helm::$tmp_dir/helm
83+
fi
84+
85+
- name: Helm Upgrade PR
86+
run: |
87+
${{steps.install-helm-client.outputs.helm}} upgrade \
88+
--install ${{steps.generate-release-name.outputs.result}} samples/BikeSharingApp/Bikes/charts/bikes \
89+
--namespace ${{steps.generate-child-space-name.outputs.result}} \
5390
--set image.repository=${{ secrets.CONTAINER_REGISTRY }}/bikes \
5491
--set image.tag=$GITHUB_SHA \
5592
--set imagePullSecrets[0].name=${{ secrets.IMAGE_PULL_SECRET }}
5693
57-
- uses: azure/dev-spaces/actions/add-review-url@Releases/v1
94+
- uses: azure/dev-spaces/actions/add-review-url@Releases/v2
5895
with:
5996
repo-token: ${{ secrets.GITHUB_TOKEN }}
60-
host: ${{ secrets.HOST }}
97+
host: ${{ secrets.HOST }}
98+
child-space: ${{steps.generate-child-space-name.outputs.result}}
99+
protocol: 'http'

.github/workflows/bikesharing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
- uses: actions/checkout@master
1717

18-
- uses: azure/docker-login@releases/v1
18+
- uses: azure/container-actions/docker-login@master
1919
with:
2020
login-server: ${{ secrets.CONTAINER_REGISTRY }}
2121
username: ${{ secrets.REGISTRY_USERNAME }}

actions/add-review-url/action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ inputs:
77
required: true
88
host: # Complete host.
99
description: "Complete host. This expands to: [rootSpace.]webfrontend.<random suffix>.<region>.azds.io. For more information see https://aka.ms/devspaces/routing"
10-
required: true
10+
required: true
11+
child-space: # Child space.
12+
description: "This is the child namespace name passed in from the workflow to construct the uri."
13+
required: true
14+
protocol: # This is an optional parameter that the user can specify (http vs https)
15+
description: "This is an optional parameter that the user can specify: example values - http or https"
16+
required: false
1117
runs:
1218
using: 'node12'
1319
main: 'lib/index.js'

actions/add-review-url/lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ function run() {
2828
const addComment = new AddReviewUrl_1.default();
2929
try {
3030
const host = core.getInput('host');
31-
let headref = process.env.GITHUB_HEAD_REF || '';
32-
const comment = `You can see a private version of the changes made in this pull request here:\nhttp://${headref}.s.${host}/`;
31+
let headref = core.getInput('child-space') || '';
32+
let protocol = core.getInput('protocol') || 'http';
33+
const comment = `You can see a private version of the changes made in this pull request here:\n${protocol}://${headref}.s.${host}/`;
3334
yield addComment.addComment(comment);
3435
}
3536
catch (error) {

actions/add-review-url/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ async function run() {
77
const addComment = new AddComment();
88
try {
99
const host = core.getInput('host');
10-
let headref = process.env.GITHUB_HEAD_REF || '';
11-
const comment = `You can see a private version of the changes made in this pull request here:\nhttp://${headref}.s.${host}/`;
10+
let headref = core.getInput('child-space') || '';
11+
let protocol = core.getInput('protocol') || 'http';
12+
const comment = `You can see a private version of the changes made in this pull request here:\n${protocol}://${headref}.s.${host}/`;
1213
await addComment.addComment(comment);
1314
}catch (error) {
1415
core.setFailed(error.message);

0 commit comments

Comments
 (0)