From 7cc2d9a41433cc15b659c747564b7a3fd54ece4e Mon Sep 17 00:00:00 2001 From: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com> Date: Wed, 23 Oct 2024 18:19:28 +0200 Subject: [PATCH 1/3] update cron logic --- .github/workflows/{update.yml => artifact_check.yml} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{update.yml => artifact_check.yml} (65%) diff --git a/.github/workflows/update.yml b/.github/workflows/artifact_check.yml similarity index 65% rename from .github/workflows/update.yml rename to .github/workflows/artifact_check.yml index 6ea98b1..8d30648 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/artifact_check.yml @@ -4,9 +4,9 @@ on: workflow_dispatch: schedule: - # https://crontab.guru/#0_22_*_*_6 - # Every saturday at 10pm - - cron: '0 22 * * 6' + # https://crontab.guru/#0_7_*_*_* + # Every saturday at 7am + - cron: '0 7 * * *' jobs: check: From 29d5e9b415717481d384706a2fc4a7994d35d36b Mon Sep 17 00:00:00 2001 From: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:35:58 +0200 Subject: [PATCH 2/3] initial commit --- .github/workflows/artifact_check.yml | 101 +++++++++++++++++++++++++-- TAG | 0 gql/.gitkeep | 0 migrations/.gitkeep | 0 4 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 TAG create mode 100644 gql/.gitkeep create mode 100644 migrations/.gitkeep diff --git a/.github/workflows/artifact_check.yml b/.github/workflows/artifact_check.yml index 8d30648..1d4c797 100644 --- a/.github/workflows/artifact_check.yml +++ b/.github/workflows/artifact_check.yml @@ -6,10 +6,101 @@ on: schedule: # https://crontab.guru/#0_7_*_*_* # Every saturday at 7am - - cron: '0 7 * * *' + - cron: "0 7 * * *" jobs: - check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 \ No newline at end of file + check_release: + runs-on: ubuntu-latest + outputs: + latest_release_tag: ${{ steps.get_latest_release.outputs.latest_release }} + new_release_found: ${{ steps.compare.outputs.new_release_found }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get latest release + id: get_latest_release + run: | + LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.PRIVATE_SG_ACCESS_TOKEN }}" https://api.github.com/repos/sourcegraph/sourcegraph/releases/latest | jq -r .tag_name) + echo "latest_release=${LATEST_RELEASE}" >> $GITHUB_OUTPUT + + - name: Read TAG file + id: read_current_tag + run: | + current_tag=$(cat TAG) + echo "current_tag=${current_tag}" >> $GITHUB_OUTPUT + + - name: Compare releases + id: compare + env: + LATEST_RELEASE: ${{ steps.get_latest_release.outputs.latest_release }} + TAG: ${{ steps.read_current_tag.outputs.current_tag }} + run: | + if [ "${LATEST_RELEASE}" == "${CURRENT_TAG}" ]; then + echo "Latest release (${LATEST_RELEASE}) matches current tag (${CURRENT_TAG})." + echo "new_release_found=false" >> $GITHUB_OUTPUT + else + echo "new_release_found=true" >> $GITHUB_OUTPUT + fi + + pull_latest_artifacts: + runs-on: ubuntu-latest + needs: [check_release] + if: needs.check_release.outputs.new_release_found == 'true' + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Update TAG file + env: + latest_release_tag: ${{ needs.check_release.outputs.latest_release_tag }} + run: echo "$latest_release_tag" > TAG + + - name: Pull database migrations + env: + latest_release_tag: ${{ needs.check_release.outputs.latest_release_tag }} + run: | + # TODO: Remove this when we start pushing schemas on every releaase. + normalized_version=$(echo "$latest_release_tag" | awk -F. '{print $1"."$2".0"}' | sed 's/^v//; s/^/v/') + file_name="migrations-${normalized_version}.tar.gz" + + # Download the tar file using curl + curl -O "https://storage.googleapis.com/schemas-migrations/migrations/$file_name" + + # extract tar file + tar -xvf "$file_name" + + # delete the tar + rm -rf "$file_name" + + - name: Commit changes + env: + latest_release_tag: ${{ needs.check_release.outputs.latest_release_tag }} + run: | + git config user.name "GitHub Action" + git config user.email "action@github.com" + git add migrations + git commit -m "Add artifacts for $latest_release_tag" + + - name: Push changes + run: | + git push origin main + + - name: Create new tag + env: + latest_release_tag: ${{ needs.check_release.outputs.latest_release_tag }} + run: | + git tag $latest_release_tag + git push origin $latest_release_tag + + - name: Create Release + env: + latest_release_tag: ${{ needs.check_release.outputs.latest_release_tag }} + run: | + RELEASE_NAME="Release $latest_release_tag" + BODY="Automatically created release with tag $latest_release_tag." + curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -d "{\"tag_name\": \"$latest_release_tag\", \"name\": \"$RELEASE_NAME\", \"body\": \"$BODY\"}" \ + "https://api.github.com/repos/${{ github.repository }}/releases" \ No newline at end of file diff --git a/TAG b/TAG new file mode 100644 index 0000000..e69de29 diff --git a/gql/.gitkeep b/gql/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/migrations/.gitkeep b/migrations/.gitkeep new file mode 100644 index 0000000..e69de29 From 63cb1d8635d6627e6180c514943302ed0ff3c473 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:36:19 +0000 Subject: [PATCH 3/3] Add renovate.json --- renovate.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..f176519 --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "local>sourcegraph/renovate-config" + ] +}