From 346e42bbb548f284bd471eba8ca6c38903e96ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wro=C5=84ski?= Date: Thu, 4 Nov 2021 15:50:56 +0100 Subject: [PATCH 1/3] Automate releases to SDKMAN --- .github/workflows/releases.yml | 34 +++++++++++++++++++++ .github/workflows/scripts/publish-sdkman.sh | 30 ++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .github/workflows/releases.yml create mode 100755 .github/workflows/scripts/publish-sdkman.sh diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml new file mode 100644 index 000000000000..735ead15b3e6 --- /dev/null +++ b/.github/workflows/releases.yml @@ -0,0 +1,34 @@ +name: Releases +on: + workflow_dispatch: + +jobs: + publish_release: + runs-on: [self-hosted, Linux] + container: + image: lampepfl/dotty:2021-03-22 + options: --cpu-shares 4096 + volumes: + - ${{ github.workspace }}/../../cache/sbt:/root/.sbt + - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache + - ${{ github.workspace }}/../../cache/general:/root/.cache + + env: + SDKMAN_KEY: ${{ secrets.SDKMAN_KEY }} + SDKMAN_TOKEN: ${{ secrets.SDKMAN_TOKEN }} + + steps: + - name: Reset existing repo + run: git -c "http.https://github.com/.extraheader=" fetch --recurse-submodules=no "https://github.com/lampepfl/dotty" && git reset --hard FETCH_HEAD || true + + - name: Checkout cleanup script + uses: actions/checkout@v2 + + - name: Cleanup + run: .github/workflows/cleanup.sh + + - name: Git Checkout + uses: actions/checkout@v2 + + - name: Publish to SDKMAN + run: .github/workflows/scripts/publish-sdkman.sh diff --git a/.github/workflows/scripts/publish-sdkman.sh b/.github/workflows/scripts/publish-sdkman.sh new file mode 100755 index 000000000000..b88834e742f5 --- /dev/null +++ b/.github/workflows/scripts/publish-sdkman.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -eu + +# latest stable dotty version +DOTTY_VERSION=$(curl -s https://api.github.com/repos/lampepfl/dotty/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') +DOTTY_URL="https://github.com/lampepfl/dotty/releases/download/$DOTTY_VERSION/scala3-$DOTTY_VERSION.zip" + +# checking if dotty version is available +if ! curl --output /dev/null --silent --head --fail "$DOTTY_URL"; then + echo "URL not exists: $DOTTY_URL" + exit 1 +fi + +# Release a new Candidate Version +curl -X POST \ + -H "Consumer-Key: $SDKMAN_KEY" \ + -H "Consumer-Token: $SDKMAN_TOKEN" \ + -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -d '{"candidate": "scala", "version": "'"$DOTTY_VERSION"'", "url": "'"$DOTTY_URL"'"}' \ + https://vendors.sdkman.io/release + +# Set DOTTY_VERSION as Default for Candidate +curl -X PUT \ + -H "Consumer-Key: $SDKMAN_KEY" \ + -H "Consumer-Token: $SDKMAN_TOKEN" \ + -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -d '{"candidate": "scala", "version": "'"$DOTTY_VERSION"'"}' \ + https://vendors.sdkman.io/default From 83a23a124ceaa598a0937bcacbe1a31ac979c1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wro=C5=84ski?= Date: Mon, 15 Nov 2021 19:05:59 +0100 Subject: [PATCH 2/3] Throw error if curl is fail and add comments --- .github/workflows/releases.yml | 10 ---------- .github/workflows/scripts/publish-sdkman.sh | 15 +++++++++++++-- docs/docs/contributing/checklist.sh | 1 + 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 735ead15b3e6..2bb6d3e49282 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -8,10 +8,6 @@ jobs: container: image: lampepfl/dotty:2021-03-22 options: --cpu-shares 4096 - volumes: - - ${{ github.workspace }}/../../cache/sbt:/root/.sbt - - ${{ github.workspace }}/../../cache/ivy:/root/.ivy2/cache - - ${{ github.workspace }}/../../cache/general:/root/.cache env: SDKMAN_KEY: ${{ secrets.SDKMAN_KEY }} @@ -21,14 +17,8 @@ jobs: - name: Reset existing repo run: git -c "http.https://github.com/.extraheader=" fetch --recurse-submodules=no "https://github.com/lampepfl/dotty" && git reset --hard FETCH_HEAD || true - - name: Checkout cleanup script - uses: actions/checkout@v2 - - name: Cleanup run: .github/workflows/cleanup.sh - - name: Git Checkout - uses: actions/checkout@v2 - - name: Publish to SDKMAN run: .github/workflows/scripts/publish-sdkman.sh diff --git a/.github/workflows/scripts/publish-sdkman.sh b/.github/workflows/scripts/publish-sdkman.sh index b88834e742f5..e489d63ef922 100755 --- a/.github/workflows/scripts/publish-sdkman.sh +++ b/.github/workflows/scripts/publish-sdkman.sh @@ -1,4 +1,12 @@ #!/usr/bin/env bash + +# This is script for publishing scala on SDKMAN. +# Script resolves the latest stable version of scala and then send REST request to SDKMAN Vendor API. +# It's releasing and announcing the release of scala on SDKMAN. +# +# Requirement: +# - the latest stable version of scala should be available in github atrifacts + set -eu # latest stable dotty version @@ -12,7 +20,8 @@ if ! curl --output /dev/null --silent --head --fail "$DOTTY_URL"; then fi # Release a new Candidate Version -curl -X POST \ +curl --silent --show-error --fail \ + -X POST \ -H "Consumer-Key: $SDKMAN_KEY" \ -H "Consumer-Token: $SDKMAN_TOKEN" \ -H "Content-Type: application/json" \ @@ -20,8 +29,10 @@ curl -X POST \ -d '{"candidate": "scala", "version": "'"$DOTTY_VERSION"'", "url": "'"$DOTTY_URL"'"}' \ https://vendors.sdkman.io/release + # Set DOTTY_VERSION as Default for Candidate -curl -X PUT \ +curl --silent --show-error --fail \ + -X PUT \ -H "Consumer-Key: $SDKMAN_KEY" \ -H "Consumer-Token: $SDKMAN_TOKEN" \ -H "Content-Type: application/json" \ diff --git a/docs/docs/contributing/checklist.sh b/docs/docs/contributing/checklist.sh index 827f0911d84d..d3cfe70b4e21 100755 --- a/docs/docs/contributing/checklist.sh +++ b/docs/docs/contributing/checklist.sh @@ -48,6 +48,7 @@ LIST='- [ ] Publish artifacts to Maven via CI - [ ] Publish Blog Post on dotty.epfl.ch - [ ] Make an announcement thread on https://contributors.scala-lang.org - [ ] Tweet the announcement blog post on https://twitter.com/scala_lang + - [ ] Run workflow releases CI to publish scala on SDKMAN - https://github.com/lampepfl/dotty/actions/workflows/releases.yml [Instructions on how to release](https://dotty.epfl.ch/docs/contributing/release.html)' From 0ed67019756e2d272595556e3024e762269b0bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wro=C5=84ski?= Date: Tue, 16 Nov 2021 14:37:39 +0100 Subject: [PATCH 3/3] Add failure test after executing curl --- .github/workflows/scripts/publish-sdkman.sh | 29 ++++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/scripts/publish-sdkman.sh b/.github/workflows/scripts/publish-sdkman.sh index e489d63ef922..07d35a72a65e 100755 --- a/.github/workflows/scripts/publish-sdkman.sh +++ b/.github/workflows/scripts/publish-sdkman.sh @@ -5,9 +5,9 @@ # It's releasing and announcing the release of scala on SDKMAN. # # Requirement: -# - the latest stable version of scala should be available in github atrifacts +# - the latest stable version of scala should be available in github artifacts -set -eu +set -u # latest stable dotty version DOTTY_VERSION=$(curl -s https://api.github.com/repos/lampepfl/dotty/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') @@ -15,20 +15,24 @@ DOTTY_URL="https://github.com/lampepfl/dotty/releases/download/$DOTTY_VERSION/sc # checking if dotty version is available if ! curl --output /dev/null --silent --head --fail "$DOTTY_URL"; then - echo "URL not exists: $DOTTY_URL" + echo "URL doesn't exist: $DOTTY_URL" exit 1 fi # Release a new Candidate Version curl --silent --show-error --fail \ - -X POST \ - -H "Consumer-Key: $SDKMAN_KEY" \ - -H "Consumer-Token: $SDKMAN_TOKEN" \ - -H "Content-Type: application/json" \ - -H "Accept: application/json" \ - -d '{"candidate": "scala", "version": "'"$DOTTY_VERSION"'", "url": "'"$DOTTY_URL"'"}' \ - https://vendors.sdkman.io/release + -X POST \ + -H "Consumer-Key: $SDKMAN_KEY" \ + -H "Consumer-Token: $SDKMAN_TOKEN" \ + -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -d '{"candidate": "scala", "version": "'"$DOTTY_VERSION"'", "url": "'"$DOTTY_URL"'"}' \ + https://vendors.sdkman.io/release +if [[ $? -ne 0 ]]; then + echo "Fail sending POST request to releasing scala on SDKMAN." + exit 1 +fi # Set DOTTY_VERSION as Default for Candidate curl --silent --show-error --fail \ @@ -39,3 +43,8 @@ curl --silent --show-error --fail \ -H "Accept: application/json" \ -d '{"candidate": "scala", "version": "'"$DOTTY_VERSION"'"}' \ https://vendors.sdkman.io/default + +if [[ $? -ne 0 ]]; then + echo "Fail sending PUT request to announcing the release of scala on SDKMAN." + exit 1 +fi