Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions .github/workflows/pullrequest.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ on:

jobs:
build:
runs-on: ubuntu-16.04
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@master

- uses: azure/container-actions/docker-login@master
- uses: azure/docker-login@v1
with:
login-server: ${{ secrets.CONTAINER_REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
Expand All @@ -47,30 +47,71 @@ jobs:
cluster-name: ${{ secrets.CLUSTER_NAME }}
resource-group: ${{ secrets.RESOURCE_GROUP }}

- name: Create valid child namespace name
id: generate-child-space-name
run: |
branch=${GITHUB_HEAD_REF::63}
branch=$(echo ${branch//[!0-9a-zA-Z]/-} | tr '[:upper:]' '[:lower:]' | sed -e 's/^-/z/' -e 's/-$/z/')
echo ::set-output name=result::$branch

- name: Create child namespaces and add Dev Spaces labels
run: |
if [ -n "$(kubectl get namespace $GITHUB_HEAD_REF --ignore-not-found -o name)" ]; then exit 0; fi
kubectl create namespace $GITHUB_HEAD_REF
kubectl label namespace $GITHUB_HEAD_REF azds.io/parent-space=${{ secrets.MASTER_SPACE }}
kubectl label namespace $GITHUB_HEAD_REF azds.io/space=true
kubectl label namespace $GITHUB_HEAD_REF azds.io/pull-request-space=true
if [ -n "$(kubectl get namespace ${{steps.generate-child-space-name.outputs.result}} --ignore-not-found -o name)" ]; then exit 0; fi
kubectl create namespace ${{steps.generate-child-space-name.outputs.result}} \
kubectl label namespace ${{steps.generate-child-space-name.outputs.result}} \
azds.io/parent-space=${{ secrets.MASTER_SPACE }} \
azds.io/space=true \
azds.io/pull-request-space=true

- uses: azure/k8s-actions/k8s-create-secret@master
with:
namespace: ${{ github.head_ref }}
namespace: ${{ steps.generate-child-space-name.outputs.result }}
container-registry-url: ${{ secrets.CONTAINER_REGISTRY }}
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
secret-name: ${{ secrets.IMAGE_PULL_SECRET }}

- name: Helm Install PR

- name: Create valid release-name
id: generate-release-name
run: |
release=<RELEASE_NAME>-$GITHUB_HEAD_REF
release=${release::53}
release=$(echo ${release//[!0-9a-zA-Z]/-} | tr '[:upper:]' '[:lower:]' | sed -e 's/^-/z/' -e 's/-$/z/')
echo ::set-output name=result::$release

- name: Install Helm for client
id: install-helm-client
run: |
set -e
clientversion=$(helm version --client --short | cut -d' ' -f2 | cut -d'+' -f1)
serverversion=$(helm version --server --short | cut -d' ' -f2 | cut -d'+' -f1)
if [ ! -n "$serverversion" ]; then
echo "Please install Helm on the server!" 1>&2
exit 1
elif [ "$clientversion" == "$serverversion" ]; then
echo The client and server Helm Versions are equal
echo ::set-output name=helm::helm
else
tmp_dir=$(mktemp -d)
export DESIRED_VERSION=$serverversion HELM_INSTALL_DIR=$tmp_dir
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh
echo ::set-output name=helm::$tmp_dir/helm
fi

- name: Helm Upgrade PR
run: |
helm upgrade --install --namespace $GITHUB_HEAD_REF <RELEASE_NAME>-$GITHUB_HEAD_REF <PATH_TO_THE_CHARTS_FOR_THAT_SERVICE> \
${{steps.install-helm-client.outputs.helm}} upgrade \
--install ${{steps.generate-release-name.outputs.result}} <PATH_TO_THE_CHARTS_FOR_THAT_SERVICE> \
--namespace ${{steps.generate-child-space-name.outputs.result}} \
--set image.repository=${{ secrets.CONTAINER_REGISTRY }}/<NAME_OF_THE_SERVICE> \
--set image.tag=$GITHUB_SHA \
--set imagePullSecrets[0].name=${{ secrets.IMAGE_PULL_SECRET }}

- uses: azure/dev-spaces/actions/add-review-url@Releases/v1
- uses: azure/dev-spaces/actions/add-review-url@Releases/v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
host: ${{ secrets.HOST }}
host: ${{ secrets.HOST }}
child-space: ${{steps.generate-child-space-name.outputs.result}}
protocol: 'http'