From 21a3e2afc422472634db1115be652ea86577fbcf Mon Sep 17 00:00:00 2001 From: Leo Ribeiro Date: Tue, 13 Aug 2024 18:38:54 -0400 Subject: [PATCH] autobump wip --- .github/workflows/bump-implementations.yml | 85 +++++++++++++++++++++- .github/workflows/test-implementations.yml | 3 +- 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bump-implementations.yml b/.github/workflows/bump-implementations.yml index a5f40314..1c248b10 100644 --- a/.github/workflows/bump-implementations.yml +++ b/.github/workflows/bump-implementations.yml @@ -1,4 +1,4 @@ -name: Test Spec Implementation Repos +name: Bump Released Spec in SDKs Repos # Parse the CI output status and make a markdown summary @@ -9,8 +9,6 @@ name: Test Spec Implementation Repos on: push: - branches: - - leordev/test-implementations tags: - "v*.*.*" workflow_dispatch: @@ -18,7 +16,6 @@ on: tag: description: "Tag (must follow pattern vN.N.N)" required: true - default: "v1.0.0" type: string jobs: @@ -65,3 +62,83 @@ jobs: fi echo "TAG=${TAG}" >> $GITHUB_OUTPUT + + - name: Generate an access token to write to downstream repo + uses: actions/create-github-app-token@2986852ad836768dfea7781f31828eb3e17990fa # v1.6.2 + id: app-token + with: + app-id: ${{ secrets.CICD_ROBOT_GITHUB_APP_ID }} + private-key: ${{ secrets.CICD_ROBOT_GITHUB_APP_PRIVATE_KEY }} + owner: TBD54566975 + repositories: ${{ matrix.repo }} + + - name: Checkout spec repository + uses: actions/checkout@v4 + with: + token: ${{ steps.app-token.outputs.token }} + repository: TBD54566975/${{ matrix.repo }} + ref: main + submodules: true + # persist-credentials: false + + - name: Setup Spec values + id: spec-vals + run: | + echo "SPEC_REF=tbd-ci-cd-robot/spec-bump" >> $GITHUB_OUTPUT + + - name: Update spec submodule in ${{ matrix.repo }} + id: bump + run: | + # initialize configs and vars + SPEC_REF=tbd-ci-cd-robot/spec-bump + TAG=${{ steps.get-tag.outputs.TAG }} + REPO_ROOT=$(pwd) + git config user.name "tbd-ci-cd-robot[bot]" + git config user.email "${{ secrets.CICD_ROBOT_GITHUB_APP_ID }}+tbd-ci-cd-robot[bot]@users.noreply.github.com" + + echo "Current directory: $(pwd)" + + # check if $SPEC_REF exists + echo "Checking if $SPEC_REF exists..." + if git ls-remote --exit-code origin $SPEC_REF; then + echo "$SPEC_REF exists, checking out..." + git fetch origin $SPEC_REF + git checkout $SPEC_REF || { echo "Failed to checkout $SPEC_REF"; exit 1; } + else + echo "$SPEC_REF doesn't exist, creating new branch..." + git checkout -b $SPEC_REF || { echo "Failed to create new branch $SPEC_REF"; exit 1; } + fi + + # bumps the spec submodule + echo "Bumping spec submodule to $TAG..." + cd ${{ matrix.spec_path }} + echo "Updating submodule..." + git submodule update --init --recursive + echo "Fetching tags..." + git fetch --all --tags + echo "Checking out $TAG..." + git checkout $TAG + + # commit changes and push + echo "Checking changes to commit..." + cd $REPO_ROOT + # only commit if needed + if git status --porcelain | grep -q '^.M'; then + git add . + git commit -m "Bump tbdex spec to $TAG" + git push origin $SPEC_REF + echo "Changes committed and pushed to $SPEC_REF" + echo "PUSHED=true" >> $GITHUB_OUTPUT + else + echo "No changes to commit" + fi + + - name: Manage autobump PR with the Changes + if: ${{ steps.bump.outputs.PUSHED == 'true' }} + run: echo "Creating PR..." + # uses: peter-evans/create-pull-request@v5 + # with: + # token: ${{ steps.app-token.outputs.token }} + # title: Bump tbdex spec to ${{ steps.get-tag.outputs.TAG }} + # body: Bumps the tbdex spec to ${{ steps.get-tag.outputs.TAG }} + # head: ${{ steps.spec-vals.outputs.SPEC_REF }} diff --git a/.github/workflows/test-implementations.yml b/.github/workflows/test-implementations.yml index 093f8045..b85c03bc 100644 --- a/.github/workflows/test-implementations.yml +++ b/.github/workflows/test-implementations.yml @@ -56,8 +56,7 @@ jobs: private-key: ${{ secrets.CICD_ROBOT_GITHUB_APP_PRIVATE_KEY }} owner: TBD54566975 repositories: ${{ matrix.repo }} - - # - name: Checkout spec repository +# - name: Checkout spec repository # uses: actions/checkout@v4 # with: # token: ${{ steps.app-token.outputs.token }}