From b96d26fcc3db0e2c1feacabb60bd951f3c581b2b Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Mon, 20 Dec 2021 12:55:39 -0500 Subject: [PATCH] Update release process and add floating tags (#441) --- .github/workflows/release-please.yml | 101 --------------------------- .github/workflows/release.yml | 94 +++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 101 deletions(-) delete mode 100644 .github/workflows/release-please.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml deleted file mode 100644 index 0d566449..00000000 --- a/.github/workflows/release-please.yml +++ /dev/null @@ -1,101 +0,0 @@ -on: - push: - branches: - - master -name: build and release-please -env: - ACTION_NAME: setup-gcloud -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: 'actions/checkout@v2' - with: - fetch-depth: '0' - - uses: 'actions/setup-node@v2' - with: - node-version: '12.x' - - name: 'npm ci' - run: 'npm ci' - - name: 'npm build' - run: 'npm run build' - - name: commit - run: |- - set -e - # get current commit hash - CURRENT_HASH=$(git rev-parse HEAD) - # get last commit hash of last build dist - LAST_BUILD_HASH=$(git log --author=google-github-actions-bot -1 --pretty=format:"%H") - DIFF="" - # build and commit dist if diff - git config --global user.name "actions-bot" - git config user.email 'github-actions-bot@google.com' - git add dist/ - git diff-index --quiet HEAD || git commit -m "chore: build dist ${{ matrix.actions }}" - # if last commit hash of last build dist was found, get logs of commits in btw for PR body - if [ -z "$LAST_BUILD_HASH" ] - then - echo "Unable to find last commit by bot, skipping diff gen" - else - DIFF=$(git log ${LAST_BUILD_HASH}...${CURRENT_HASH} --oneline) - echo $DIFF - fi - # set env vars - echo "CURRENT_HASH=${CURRENT_HASH}" >> $GITHUB_ENV - echo "LAST_BUILD_HASH=${LAST_BUILD_HASH}" >> $GITHUB_ENV - echo 'DIFF<> $GITHUB_ENV - echo "${DIFF}" >> $GITHUB_ENV - echo 'EOF' >> $GITHUB_ENV - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - with: - token: ${{ secrets.ACTIONS_BOT_TOKEN }} - commit-message: Build dist - author: "actions-bot " - title: "chore: build dist ${{ matrix.actions }}" - body: | - Build dist PR - ${{env.DIFF}} - labels: automated pr - branch: create-pull-request/build-dist-${{ matrix.actions }} - delete-branch: true - push-to-fork: google-github-actions-bot/setup-gcloud - release-please-pr: - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: google-github-actions/release-please-action@v2 - with: - token: ${{ secrets.ACTIONS_BOT_TOKEN }} - release-type: node - bump-minor-pre-major: true - fork: true - package-name: ${{env.ACTION_NAME}} - command: release-pr - release-please-release: - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: google-github-actions/release-please-action@v2 - id: release - with: - token: ${{ secrets.GITHUB_TOKEN }} - release-type: node - bump-minor-pre-major: true - package-name: ${{env.ACTION_NAME}} - command: github-release - - uses: actions/checkout@v2 - - name: tag major and patch versions - if: ${{ steps.release.outputs.release_created }} - run: | - git config user.name github-actions[bot] - git config user.email 41898282+github-actions[bot]@users.noreply.github.com - git remote add gh-token "https://${{ secrets.GITHUB_TOKEN}}@github.com/google-github-actions/${{env.ACTION_NAME}}.git" - git tag -d v${{ steps.release.outputs.major }} || true - git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true - git push origin :v${{ steps.release.outputs.major }} || true - git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true - git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}" - git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}" - git push origin v${{ steps.release.outputs.major }} - git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..cc8d5194 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,94 @@ +name: 'release' + +on: + push: + branches: + - 'main' + workflow_dispatch: + +jobs: + # build compiles the code and creates a pull request of the compiled result if + # there is a diff. + build: + runs-on: 'ubuntu-latest' + steps: + - uses: 'actions/checkout@v2' + + - uses: 'actions/setup-node@v2' + with: + node-version: '12.x' + + - name: 'npm build' + run: 'npm ci && npm run build' + + - name: 'Create pull request' + uses: 'peter-evans/create-pull-request@dcd5fd746d53dd8de555c0f10bca6c35628be47a' + with: + token: '${{ secrets.ACTIONS_BOT_TOKEN }}' + add-paths: 'dist/' + committer: 'google-github-actions-bot ' + author: 'google-github-actions-bot ' + signoff: 'google-github-actions-bot ' + commit-message: 'Build dist' + title: 'chore: build dist' + body: 'Build compiled Typescript' + base: 'main' + branch: 'actions/build' + push-to-fork: 'google-github-actions-bot/setup-gcloud' + delete-branch: true + + # create-pull-request creates a release pull request if there are any + # convential commit changes since the last release. + create-pull-request: + runs-on: 'ubuntu-latest' + steps: + - uses: 'google-github-actions/release-please-action@v2' + with: + token: '${{ secrets.ACTIONS_BOT_TOKEN }}' + release-type: 'node' + bump-minor-pre-major: true + command: 'release-pr' + fork: true + + # release does a release on the merge of the release pull request. It also + # updates the floating tag alias for the major version. + release: + runs-on: 'ubuntu-latest' + steps: + - id: 'release' + uses: 'google-github-actions/release-please-action@v2' + with: + release-type: 'node' + bump-minor-pre-major: true + command: 'github-release' + + - name: 'Update floating tag' + if: '${{ steps.release.outputs.release_created }}' + uses: 'actions/github-script@v5' + with: + script: |- + const sha = '${{ steps.release.outputs.sha }}' + const major = 'v${{ steps.release.outputs.major }}'; + + // Try to update the ref first. If that fails, it probably does not + // exist yet, and we should create it. + try { + await github.rest.git.updateRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `tags/${major}`, + sha: sha, + force: true, + }); + core.info(`Updated ${major} to ${sha}`); + } catch(err) { + core.warning(`Failed to create ${major}: ${err}`); + + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/tags/${major}`, + sha: sha, + }); + core.info(`Created ${major} at ${sha}`); + }