diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 970c83d78..1e5846562 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,9 @@ on: push: branches-ignore: - 'experiements/**' + create: + tags: + - '*' pull_request: branches: - master @@ -13,7 +16,8 @@ jobs: name: Code Style and Build Config runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Clone GraalSqueak repository + uses: actions/checkout@v2 - name: Check style and perform full build run: | # Install pylint @@ -44,10 +48,10 @@ jobs: name: Test on Linux with Coverage runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Checkout submodules - shell: bash - run: git submodule update --init --recursive + - name: Clone GraalSqueak repository + uses: actions/checkout@v2 + with: + submodules: true - name: Set up dependencies shell: bash run: | @@ -89,19 +93,16 @@ jobs: - name: Run tinyBenchmarks on Native Image run: graalsqueak --native --code "1 tinyBenchmarks" images/test-64bit.image - name: Upload GraalSqueak component - uses: actions/upload-artifact@v1 - with: - name: ${{ env.INSTALLABLE_TARGET }} - path: ${{ env.INSTALLABLE_TARGET }} + run: mx.graalsqueak/utils.sh deploy-asset ${{ github.ref }} ${{ env.INSTALLABLE_TARGET }} ${{ secrets.GITHUB_TOKEN }} macos: name: Test on macOS with Graal runs-on: macos-latest steps: - - uses: actions/checkout@v2 - - name: Checkout submodules - shell: bash - run: git submodule update --init --recursive + - name: Clone GraalSqueak repository + uses: actions/checkout@v2 + with: + submodules: true - name: Set up dependencies shell: bash run: | @@ -135,19 +136,16 @@ jobs: - name: Run tinyBenchmarks on Native Image run: graalsqueak --native --code "1 tinyBenchmarks" images/test-64bit.image - name: Upload GraalSqueak component - uses: actions/upload-artifact@v1 - with: - name: ${{ env.INSTALLABLE_TARGET }} - path: ${{ env.INSTALLABLE_TARGET }} + run: mx.graalsqueak/utils.sh deploy-asset ${{ github.ref }} ${{ env.INSTALLABLE_TARGET }} ${{ secrets.GITHUB_TOKEN }} windows: name: Test on Windows runs-on: windows-latest steps: - - uses: actions/checkout@v2 - - name: Checkout submodules - shell: bash - run: git submodule update --init --recursive + - name: Clone GraalSqueak repository + uses: actions/checkout@v2 + with: + submodules: true - name: Set up dependencies shell: bash run: | @@ -175,7 +173,5 @@ jobs: - name: Run tinyBenchmarks on GraalVM run: graalsqueak.cmd --jvm --code "1 tinyBenchmarks" images/test-64bit.image - name: Upload GraalSqueak component - uses: actions/upload-artifact@v1 - with: - name: ${{ env.INSTALLABLE_TARGET }} - path: ${{ env.INSTALLABLE_TARGET }} + shell: bash + run: mx.graalsqueak/utils.sh deploy-asset ${{ github.ref }} ${{ env.INSTALLABLE_TARGET }} ${{ secrets.GITHUB_TOKEN }} diff --git a/mx.graalsqueak/utils.sh b/mx.graalsqueak/utils.sh index 8bfdd2ee8..f81b87b48 100755 --- a/mx.graalsqueak/utils.sh +++ b/mx.graalsqueak/utils.sh @@ -31,6 +31,55 @@ OS_NAME=$(uname -s | tr '[:upper:]' '[:lower:]') JAVA_HOME_SUFFIX="" && [[ "${OS_NAME}" == "darwin" ]] && JAVA_HOME_SUFFIX="/Contents/Home" readonly OS_NAME JAVA_HOME_SUFFIX + +deploy-asset() { + if ! [[ "$1" =~ ^refs\/tags\/[[:digit:]] ]]; then + echo "Skipping deployment step (ref does not start with a digit)" + exit 0 + fi + local git_ref=${1:10} # cut off 'refs/tags/' + local filename=$2 + local auth="Authorization: token $3" + local release_id + + tag_result=$(curl -L --retry 3 --retry-connrefused --retry-delay 2 -sH "${auth}" \ + "https://api.github.com/repos/${GITHUB_SLUG}/releases/tags/${git_ref}") + + if echo "${tag_result}" | grep -q '"id":'; then + release_id=$(echo "${tag_result}" | grep '"id":' | head -n 1 | sed 's/[^0-9]*//g') + echo "Found GitHub release #${release_id} for ${git_ref}" + else + # Retry (in case release was just created by some other worker) + tag_result=$(curl -L --retry 3 --retry-connrefused --retry-delay 2 -sH "${auth}" \ + "https://api.github.com/repos/${GITHUB_SLUG}/releases/tags/${git_ref}") + + if echo "${tag_result}" | grep -q '"id":'; then + release_id=$(echo "${tag_result}" | grep '"id":' | head -n 1 | sed 's/[^0-9]*//g') + echo "Found GitHub release #${release_id} for ${git_ref}" + else + create_result=$(curl -sH "${auth}" \ + --data "{\"tag_name\": \"${git_ref}\", + \"name\": \"${git_ref}\", + \"body\": \"\", + \"draft\": false, + \"prerelease\": false}" \ + "https://api.github.com/repos/${GITHUB_SLUG}/releases") + if echo "${create_result}" | grep -q '"id":'; then + release_id=$(echo "${create_result}" | grep '"id":' | head -n 1 | sed 's/[^0-9]*//g') + echo "Created GitHub release #${release_id} for ${git_ref}" + else + echo "Failed to create GitHub release for ${git_ref}" + exit 1 + fi + fi + fi + + curl --fail -o /dev/null -w "%{http_code}" \ + -H "${auth}" -H "Content-Type: application/zip" \ + --data-binary @"${filename}" \ + "https://uploads.github.com/repos/${GITHUB_SLUG}/releases/${release_id}/assets?name=${filename}" +} + download-asset() { local filename=$1 local git_tag=$2