Skip to content

Commit

Permalink
Create doc PR on release (#2687)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Nov 11, 2022
1 parent e69bbcc commit 7bf50a8
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 39 deletions.
57 changes: 19 additions & 38 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
jobs:
release:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.create-github-release.outputs.version }}
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -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"
Expand All @@ -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 }}
85 changes: 85 additions & 0 deletions .github/workflows/reusable-create-docs-pull-request.yml
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions .github/workflows/reusable-create-version-bump-pull-request.yml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion .github/workflows/reusable-open-issue-on-failure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)."

0 comments on commit 7bf50a8

Please sign in to comment.