From 039e15fc84465fd2595d4fc74bf817a44ba371ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 17 Sep 2024 12:31:46 +0100 Subject: [PATCH] ci: make canary uploads less racy (#25671) Closes https://github.com/denoland/deno/issues/25464 Only uploads canary git hash if the one in the bucket is present in the current action Git history. --- .github/workflows/ci.generate.ts | 16 ++++++++++++---- .github/workflows/ci.yml | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.generate.ts b/.github/workflows/ci.generate.ts index 8cc57619b2..608bb30480 100755 --- a/.github/workflows/ci.generate.ts +++ b/.github/workflows/ci.generate.ts @@ -813,8 +813,12 @@ const ci = { ].join("\n"), run: [ 'gsutil -h "Cache-Control: public, max-age=3600" cp ./target/release/*.zip gs://dl.deno.land/canary/$(git rev-parse HEAD)/', - "echo ${{ github.sha }} > canary-latest.txt", - 'gsutil -h "Cache-Control: no-cache" cp canary-latest.txt gs://dl.deno.land/canary-$(rustc -vV | sed -n "s|host: ||p")-latest.txt', + 'lastest_canary_hash=$(gsutil cat gs://dl.deno.land/canary-$(rustc -vV | sed -n "s|host: ||p")-latest.txt)', + "git cat-file -e $(lastest_canary_hash)", + "if [ $? -eq 0 ]; then", + " echo ${{ github.sha }} > canary-latest.txt", + ' gsutil -h "Cache-Control: no-cache" cp canary-latest.txt gs://dl.deno.land/canary-$(rustc -vV | sed -n "s|host: ||p")-latest.txt', + "fi", ].join("\n"), }, { @@ -1092,8 +1096,12 @@ const ci = { { name: "Upload canary version file to dl.deno.land", run: [ - "echo ${{ github.sha }} > canary-latest.txt", - 'gsutil -h "Cache-Control: no-cache" cp canary-latest.txt gs://dl.deno.land/canary-latest.txt', + "lastest_canary_hash=$(gsutil cat gs://dl.deno.land/canary-latest.txt) && \\", + "git cat-file -e $(lastest_canary_hash)", + "if [ $? -eq 0]; then", + " echo ${{ github.sha }} > canary-latest.txt && \\", + ' gsutil -h "Cache-Control: no-cache" cp canary-latest.txt gs://dl.deno.land/canary-latest.txt', + "fi", ].join("\n"), }, ], diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a10f40630..e9f7bff073 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -486,8 +486,12 @@ jobs: github.ref == 'refs/heads/main') run: |- gsutil -h "Cache-Control: public, max-age=3600" cp ./target/release/*.zip gs://dl.deno.land/canary/$(git rev-parse HEAD)/ - echo ${{ github.sha }} > canary-latest.txt - gsutil -h "Cache-Control: no-cache" cp canary-latest.txt gs://dl.deno.land/canary-$(rustc -vV | sed -n "s|host: ||p")-latest.txt + lastest_canary_hash=$(gsutil cat gs://dl.deno.land/canary-$(rustc -vV | sed -n "s|host: ||p")-latest.txt) + git cat-file -e $(lastest_canary_hash) + if [ $? -eq 0 ]; then + echo ${{ github.sha }} > canary-latest.txt + gsutil -h "Cache-Control: no-cache" cp canary-latest.txt gs://dl.deno.land/canary-$(rustc -vV | sed -n "s|host: ||p")-latest.txt + fi - name: Autobahn testsuite if: |- !(matrix.skip) && ((matrix.os == 'linux' && matrix.arch != 'aarch64') && @@ -690,5 +694,9 @@ jobs: project_id: denoland - name: Upload canary version file to dl.deno.land run: |- - echo ${{ github.sha }} > canary-latest.txt - gsutil -h "Cache-Control: no-cache" cp canary-latest.txt gs://dl.deno.land/canary-latest.txt + lastest_canary_hash=$(gsutil cat gs://dl.deno.land/canary-latest.txt) && \ + git cat-file -e $(lastest_canary_hash) + if [ $? -eq 0]; then + echo ${{ github.sha }} > canary-latest.txt && \ + gsutil -h "Cache-Control: no-cache" cp canary-latest.txt gs://dl.deno.land/canary-latest.txt + fi