From 7bf50a863e93a1037f996c035e0683df35d76800 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 11 Nov 2022 15:48:11 -0800 Subject: [PATCH] Create doc PR on release (#2687) --- .github/workflows/release.yml | 57 +++++-------- .../reusable-create-docs-pull-request.yml | 85 +++++++++++++++++++ ...sable-create-version-bump-pull-request.yml | 55 ++++++++++++ .../reusable-open-issue-on-failure.yml | 2 +- 4 files changed, 160 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/reusable-create-docs-pull-request.yml create mode 100644 .github/workflows/reusable-create-version-bump-pull-request.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5a6c16f00f1..a61fa463ba0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,8 @@ on: jobs: release: runs-on: ubuntu-latest + outputs: + version: ${{ steps.create-github-release.outputs.version }} steps: - uses: actions/checkout@v3 @@ -33,12 +35,12 @@ jobs: sleep 60 done - - name: Create GitHub release + - id: create-github-release + name: Create GitHub release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - then opt_ga=" (GA)" else opt_prerelease="--prerelease" @@ -52,41 +54,20 @@ jobs: $VERSION \ applicationinsights-agent-$VERSION.jar - bump-version: - runs-on: ubuntu-latest + echo "::set-output name=version::$VERSION" + + create-docs-pull-request: needs: - release - steps: - - uses: actions/checkout@v3 + uses: ./.github/workflows/reusable-create-docs-pull-request.yml + with: + version: ${{ needs.release.outputs.version }} + secrets: + AARON_MAXWELL_TOKEN: ${{ secrets.AARON_MAXWELL_TOKEN }} - - name: Set environment variables - run: | - version=$(.github/scripts/get-version.sh) - if [[ $version =~ ^([0-9]+\.[0-9]+)\.([0-9]+)$ ]]; then - major_minor="${BASH_REMATCH[1]}" - patch="${BASH_REMATCH[2]}" - else - echo "unexpected version: $version" - exit 1 - fi - echo "NEXT_VERSION=$major_minor.$((patch + 1))" >> $GITHUB_ENV - - - name: Update version - run: .github/scripts/update-version.sh $NEXT_VERSION - - - name: Create pull request against main - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - message="Update version to $NEXT_VERSION" - body="Update version to \`$NEXT_VERSION\`." - branch="automation/update-version-to-${NEXT_VERSION}" - - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - git checkout -b "$branch" - git commit -a -m "$message" - git push --set-upstream origin HEAD:$branch - gh pr create --title "$message" \ - --body "$body" + create-version-bump-pull-request: + needs: + - release + uses: ./.github/workflows/reusable-create-version-bump-pull-request.yml + with: + version: ${{ needs.release.outputs.version }} diff --git a/.github/workflows/reusable-create-docs-pull-request.yml b/.github/workflows/reusable-create-docs-pull-request.yml new file mode 100644 index 00000000000..4892befc48b --- /dev/null +++ b/.github/workflows/reusable-create-docs-pull-request.yml @@ -0,0 +1,85 @@ +name: Reusable - Create docs pull request + +on: + workflow_call: + inputs: + version: + type: string + required: true + secrets: + AARON_MAXWELL_TOKEN: + required: true + # to help with partial release build failures + workflow_dispatch: + inputs: + version: + description: "Version" + required: true + +jobs: + create-docs-pull-request: + runs-on: ubuntu-latest + steps: + - name: Repo sync + # this step avoids having to do a deep fetch of the very large upstream repo + # (cannot use "git fetch --depth 1 upstream main" because that leads to an error when + # pushing below to the origin repo: "shallow update not allowed") + env: + VERSION: ${{ inputs.version }} + # this is the personal access token used for "gh repo sync" below + GH_TOKEN: ${{ secrets.AARON_MAXWELL_TOKEN }} + run: | + gh repo sync AaronMaxwell/azure-docs-pr \ + --source MicrosoftDocs/azure-docs-pr + + - uses: actions/checkout@v3 + with: + repository: AaronMaxwell/azure-docs-pr + # this is the personal access token used for "git push" below + token: ${{ secrets.AARON_MAXWELL_TOKEN }} + + - name: Update version in docs + env: + VERSION: ${{ inputs.version }} + run: | + date=$(date "+%m/%d/%Y") + files=$(grep -rl applicationinsights-agent-[0-9.]*.jar articles/azure-monitor/app \ + | grep -v java-2x-agent.md) + echo "$files" | xargs sed -Ei "s/applicationinsights-agent-[0-9.]+.jar/applicationinsights-agent-${VERSION}.jar/g" + echo "$files" | xargs sed -Ei "s|microsoft/ApplicationInsights-Java/releases/download/[0-9.]*/|microsoft/ApplicationInsights-Java/releases/download/${VERSION}/|g" + echo "$files" | xargs sed -Ei "s|^ms.date: .*|ms.date: $date|" + + - name: Create pull request against azure-docs-pr + env: + VERSION: ${{ inputs.version }} + # this is the personal access token used for "gh pr create" below + GH_TOKEN: ${{ secrets.AARON_MAXWELL_TOKEN }} + run: | + message="Update the applicationinsights-java version to $VERSION" + body="Update the applicationinsights-java version to \`$VERSION\`. + + cc @AaronMaxwell @heyams @jeanbisutti @mattmccleary @trask + " + branch="update-applicationinsights-java-to-${VERSION}" + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git checkout -b $branch + git commit -a -m "$message" + git push --set-upstream origin $branch + + # gh pr create doesn't have a way to explicitly specify different head and base + # repositories currently, but it will implicitly pick up the head from a different + # repository if you set up a tracking branch + + echo ======================================== + echo To create PR, go to + echo https://github.com/MicrosoftDocs/azure-docs-pr/compare/main...AaronMaxwell:azure-docs-pr:${branch}?expand=1 + echo ======================================== + + # TODO (trask) create PR automatically + # gh pr create --title "$message" \ + # --body "$body" \ + # --repo MicrosoftDocs/azure-docs-pr \ + # --base main diff --git a/.github/workflows/reusable-create-version-bump-pull-request.yml b/.github/workflows/reusable-create-version-bump-pull-request.yml new file mode 100644 index 00000000000..9968b2f43d8 --- /dev/null +++ b/.github/workflows/reusable-create-version-bump-pull-request.yml @@ -0,0 +1,55 @@ +name: Reusable - Create version bump pull request + +on: + workflow_call: + inputs: + version: + type: string + required: true + # to help with partial release build failures + workflow_dispatch: + inputs: + version: + description: "Version" + required: true + +jobs: + bump-version: + runs-on: ubuntu-latest + needs: + - release + steps: + - uses: actions/checkout@v3 + + - name: Set environment variables + env: + VERSION: ${{ inputs.version }} + run: | + if [[ $VERSION =~ ^([0-9]+\.[0-9]+)\.([0-9]+)$ ]]; then + major_minor="${BASH_REMATCH[1]}" + patch="${BASH_REMATCH[2]}" + else + echo "unexpected version: $VERSION" + exit 1 + fi + echo "NEXT_VERSION=$major_minor.$((patch + 1))" >> $GITHUB_ENV + + - name: Update version + run: .github/scripts/update-version.sh $NEXT_VERSION + + - name: Create pull request against main + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + message="Update version to $NEXT_VERSION" + body="Update version to \`$NEXT_VERSION\`." + branch="automation/update-version-to-${NEXT_VERSION}" + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git checkout -b "$branch" + git commit -a -m "$message" + git push --set-upstream origin HEAD:$branch + gh pr create --title "$message" \ + --body "$body" diff --git a/.github/workflows/reusable-open-issue-on-failure.yml b/.github/workflows/reusable-open-issue-on-failure.yml index 984ce7435d5..9d1e6d2d703 100644 --- a/.github/workflows/reusable-open-issue-on-failure.yml +++ b/.github/workflows/reusable-open-issue-on-failure.yml @@ -11,7 +11,7 @@ jobs: - name: Open issue env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh issue create --title "$GITHUB_WORKFLOW #$GITHUB_RUN_NUMBER failed" \ --body "See [$GITHUB_WORKFLOW #$GITHUB_RUN_NUMBER](https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)."