diff --git a/.github/workflows/pullrequest.yml.template b/.github/workflows/pullrequest.yml.template index 62e41205f..364ac7137 100644 --- a/.github/workflows/pullrequest.yml.template +++ b/.github/workflows/pullrequest.yml.template @@ -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 }} @@ -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=-$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 -$GITHUB_HEAD_REF \ + ${{steps.install-helm-client.outputs.helm}} upgrade \ + --install ${{steps.generate-release-name.outputs.result}} \ + --namespace ${{steps.generate-child-space-name.outputs.result}} \ --set image.repository=${{ secrets.CONTAINER_REGISTRY }}/ \ --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 }} \ No newline at end of file + host: ${{ secrets.HOST }} + child-space: ${{steps.generate-child-space-name.outputs.result}} + protocol: 'http' \ No newline at end of file