diff --git a/.github/workflows/bikes.yml b/.github/workflows/bikes.yml index e639d0c17..1887b9062 100644 --- a/.github/workflows/bikes.yml +++ b/.github/workflows/bikes.yml @@ -10,11 +10,10 @@ on: jobs: build: runs-on: ubuntu-latest - steps: - - - uses: actions/checkout@master - - - uses: azure/docker-login@releases/v1 + steps: + - uses: actions/checkout@master + + - uses: azure/docker-login@v1 with: login-server: ${{ secrets.CONTAINER_REGISTRY }} username: ${{ secrets.REGISTRY_USERNAME }} @@ -29,32 +28,72 @@ jobs: creds: '${{ secrets.AZURE_CREDENTIALS }}' 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: | - helm init --upgrade --wait - helm upgrade --install --namespace $GITHUB_HEAD_REF bikesharing-$GITHUB_HEAD_REF samples/BikeSharingApp/Bikes/charts/bikes \ + release=bikesharing-$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: | + ${{steps.install-helm-client.outputs.helm}} upgrade \ + --install ${{steps.generate-release-name.outputs.result}} samples/BikeSharingApp/Bikes/charts/bikes \ + --namespace ${{steps.generate-child-space-name.outputs.result}} \ --set image.repository=${{ secrets.CONTAINER_REGISTRY }}/bikes \ --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 diff --git a/.github/workflows/bikesharing.yml b/.github/workflows/bikesharing.yml index 25f85e37e..03ee165a2 100644 --- a/.github/workflows/bikesharing.yml +++ b/.github/workflows/bikesharing.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@master - - uses: azure/docker-login@releases/v1 + - uses: azure/container-actions/docker-login@master with: login-server: ${{ secrets.CONTAINER_REGISTRY }} username: ${{ secrets.REGISTRY_USERNAME }} diff --git a/actions/add-review-url/action.yml b/actions/add-review-url/action.yml index 37df34a10..7ebf28392 100644 --- a/actions/add-review-url/action.yml +++ b/actions/add-review-url/action.yml @@ -7,7 +7,13 @@ inputs: required: true host: # Complete host. description: "Complete host. This expands to: [rootSpace.]webfrontend...azds.io. For more information see https://aka.ms/devspaces/routing" - required: true + required: true + child-space: # Child space. + description: "This is the child namespace name passed in from the workflow to construct the uri." + required: true + protocol: # This is an optional parameter that the user can specify (http vs https) + description: "This is an optional parameter that the user can specify: example values - http or https" + required: false runs: using: 'node12' main: 'lib/index.js' \ No newline at end of file diff --git a/actions/add-review-url/lib/index.js b/actions/add-review-url/lib/index.js index 3e0134e52..c8f27abaa 100644 --- a/actions/add-review-url/lib/index.js +++ b/actions/add-review-url/lib/index.js @@ -28,8 +28,9 @@ function run() { const addComment = new AddReviewUrl_1.default(); try { const host = core.getInput('host'); - let headref = process.env.GITHUB_HEAD_REF || ''; - const comment = `You can see a private version of the changes made in this pull request here:\nhttp://${headref}.s.${host}/`; + let headref = core.getInput('child-space') || ''; + let protocol = core.getInput('protocol') || 'http'; + const comment = `You can see a private version of the changes made in this pull request here:\n${protocol}://${headref}.s.${host}/`; yield addComment.addComment(comment); } catch (error) { diff --git a/actions/add-review-url/src/index.ts b/actions/add-review-url/src/index.ts index ab4308a3a..866aa4936 100644 --- a/actions/add-review-url/src/index.ts +++ b/actions/add-review-url/src/index.ts @@ -7,8 +7,9 @@ async function run() { const addComment = new AddComment(); try { const host = core.getInput('host'); - let headref = process.env.GITHUB_HEAD_REF || ''; - const comment = `You can see a private version of the changes made in this pull request here:\nhttp://${headref}.s.${host}/`; + let headref = core.getInput('child-space') || ''; + let protocol = core.getInput('protocol') || 'http'; + const comment = `You can see a private version of the changes made in this pull request here:\n${protocol}://${headref}.s.${host}/`; await addComment.addComment(comment); }catch (error) { core.setFailed(error.message);