From 89786e77ff3873cb28dd3922416cfc3edcdfffe0 Mon Sep 17 00:00:00 2001 From: Aditya Maru Date: Fri, 4 Oct 2024 18:01:46 -0700 Subject: [PATCH] add automation to bump cache version --- .github/workflows/bump-cache-version.yml | 51 ++++++++++++++++++++++++ .github/workflows/bump-tag.yml | 33 +++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 .github/workflows/bump-cache-version.yml create mode 100644 .github/workflows/bump-tag.yml diff --git a/.github/workflows/bump-cache-version.yml b/.github/workflows/bump-cache-version.yml new file mode 100644 index 000000000..cd2befdae --- /dev/null +++ b/.github/workflows/bump-cache-version.yml @@ -0,0 +1,51 @@ +name: Bump Cache Version + +on: + workflow_dispatch: + inputs: + cache_version: + description: "New @useblacksmith/cache version" + required: true + type: string + +jobs: + bump-cache-version: + runs-on: blacksmith + steps: + - uses: actions/checkout@v4 + + - name: Create new branch + id: create-branch + run: | + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + git fetch origin main + git checkout main + git pull origin main + timestamp=$(date +%Y%m%d%H%M%S) + branch_name="bump-cache-version-${{ github.event.inputs.cache_version }}-$timestamp" + git checkout -b $branch_name + echo "branch_name=$branch_name" >> $GITHUB_OUTPUT + + - name: Update package.json + run: | + sed -i 's/"@actions\/cache": "npm:@useblacksmith\/cache@[^"]*"/"@actions\/cache": "npm:@useblacksmith\/cache@${{ github.event.inputs.cache_version }}"/' package.json + - name: Install dependencies + run: npm install + + - name: Build + run: npm run build + + - name: Check for changes + id: git-check + run: | + git diff --exit-code || echo "changes=true" >> $GITHUB_OUTPUT + - name: Create Pull Request + if: steps.git-check.outputs.changes == 'true' + env: + GH_TOKEN: ${{ github.token }} + run: | + git add . + git commit -m "Bump @actions/cache version to ${{ github.event.inputs.cache_version }}" + git push origin ${{ steps.create-branch.outputs.branch_name }} + gh pr create --title "Bump @actions/cache version to ${{ github.event.inputs.cache_version }}" --body "This PR updates the @actions/cache version to ${{ github.event.inputs.cache_version }}" \ No newline at end of file diff --git a/.github/workflows/bump-tag.yml b/.github/workflows/bump-tag.yml new file mode 100644 index 000000000..0b98d3df6 --- /dev/null +++ b/.github/workflows/bump-tag.yml @@ -0,0 +1,33 @@ +name: Bump Tags on Main + +on: + push: + branches: + - main + +jobs: + bump-tags: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Update v5 and v5.0.1 tags + run: | + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + git tag -fa v5 -m "Update v5 tag to latest commit on main" + git tag -fa v5.0.1 -m "Update v5.0.1 tag to latest commit on main" + git push origin v5 v5.0.1 --force + + - name: Send Slack notification on success + uses: slackapi/slack-github-action@v1 + with: + payload: | + { + "text": "Updated setup-java v5 and v5.0.1 tags to the latest commit on main" + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.CACHE_SLACK_WEBHOOK_URL }}