Repository navigation
Automate releases from webrtc-build #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fe50339
Automate releases from webrtc-build
cloudwebrtc dea825b
prepare-release: open the release PR with a GitHub App token
cloudwebrtc fdc2ccd
release: queue pending release runs
cloudwebrtc ab83c7e
prepare-release: skip versions already prepared; require a two-digit …
cloudwebrtc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env python3 | ||
| """Bump the android repository to a new WebRTC release. | ||
|
|
||
| prepare_release.py --version 150.7871.08 [--commit <webrtc sha>] \ | ||
| [--webrtc-repo webrtc-sdk/webrtc] [--date 2026.11.16] | ||
|
|
||
| Updates VERSION_NAME in gradle.properties, the dependency versions in | ||
| README.md and adds a CHANGES.md entry. | ||
| """ | ||
|
|
||
| import argparse | ||
| import datetime | ||
| import os | ||
| import re | ||
|
|
||
| ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
| ARTIFACTS = ['android', 'android-prefixed', 'android-prefixed-stripped'] | ||
|
|
||
|
|
||
| def sub(path: str, pattern: str, repl: str, count: int = 1, flags=0): | ||
| with open(path) as f: | ||
| text = f.read() | ||
| new, n = re.subn(pattern, repl, text, count=count, flags=flags) | ||
| if n == 0: | ||
| raise SystemExit(f'{os.path.basename(path)}: pattern not found: {pattern}') | ||
| with open(path, 'w', newline='\n') as f: | ||
| f.write(new) | ||
|
|
||
|
|
||
| def main(): | ||
| p = argparse.ArgumentParser(description=__doc__.split('\n')[0]) | ||
| p.add_argument('--version', required=True) | ||
| p.add_argument('--commit', default='', help='webrtc commit the binaries were built from') | ||
| p.add_argument('--webrtc-repo', default='webrtc-sdk/webrtc') | ||
| p.add_argument('--date', default=datetime.date.today().strftime('%Y.%m.%d')) | ||
| args = p.parse_args() | ||
|
|
||
| v = args.version | ||
| # Two-digit patch (150.7871.08, not 150.7871.8), as in webrtc-build. | ||
| if not re.fullmatch(r'\d+\.\d+\.(\d{2}|[1-9]\d{2,})', v): | ||
| raise SystemExit(f'invalid version {v!r}: expected <milestone>.<branch>.<patch> ' | ||
| 'with a two-digit patch, e.g. 150.7871.08') | ||
| path = lambda name: os.path.join(ROOT, name) | ||
|
|
||
| # A replayed notification for a release already on this branch (its | ||
| # release PR was merged) is a no-op: no file changes means no PR. An | ||
| # outstanding release PR is regenerated from the base branch, which does | ||
| # not have the version yet, so it is still updated. | ||
| with open(path('gradle.properties')) as f: | ||
| current = re.search(r'^VERSION_NAME=(.*)$', f.read(), re.M) | ||
| with open(path('CHANGES.md')) as f: | ||
| logged = re.search(rf'^\[{re.escape(v)}\] - ', f.read(), re.M) | ||
| if (current and current.group(1).strip() == v) or logged: | ||
| print(f'{v} is already prepared on this branch; nothing to do') | ||
| return | ||
|
|
||
| sub(path('gradle.properties'), r'^VERSION_NAME=.*$', f'VERSION_NAME={v}', flags=re.M) | ||
| for artifact in ARTIFACTS: | ||
| sub(path('README.md'), rf"(io\.github\.webrtc-sdk:{re.escape(artifact)}:)[0-9.]+", rf'\g<1>{v}', count=0) | ||
|
|
||
| milestone, branch, patch = v.split('.') | ||
| entry = f'[{v}] - {args.date}\n\n* Upgrade to WebRTC-SDK M{milestone}.{branch}.{patch}\n\n' | ||
| if args.commit: | ||
| entry += f'Corresponds to https://github.com/{args.webrtc_repo}/commit/{args.commit}\n\n' | ||
| sub(path('CHANGES.md'), r'(-{10,}\n)', rf'\g<1>{entry}') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| name: prepare-release | ||
|
|
||
| # Opens release/<version> when webrtc-build publishes a release | ||
| # (repository_dispatch `webrtc-release`), or by hand. The PR bumps | ||
| # VERSION_NAME, README.md and CHANGES.md. Merging it runs release.yml. | ||
|
|
||
| on: | ||
| repository_dispatch: | ||
| types: [webrtc-release] | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: 'Version, e.g. 150.7871.08 (webrtc-build release m<version> must exist)' | ||
| required: true | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| env: | ||
| SOURCE_REPO: ${{ github.event.client_payload.source_repo || vars.SOURCE_REPO || 'webrtc-sdk/webrtc-build' }} | ||
| VERSION: ${{ github.event.client_payload.version || inputs.version }} | ||
|
|
||
| jobs: | ||
| open: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # Pushes and PRs made with a GitHub App token trigger workflows (the PR | ||
| # checks); GITHUB_TOKEN ones do not. Skipped when the App is not set up. | ||
| - name: Create GitHub App token | ||
| id: app | ||
| if: vars.RELEASE_APP_CLIENT_ID != '' | ||
| uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 | ||
| with: | ||
| client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} | ||
| private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} | ||
| permission-contents: write | ||
| permission-pull-requests: write | ||
| permission-issues: write | ||
| - uses: actions/checkout@v5 | ||
| - name: Bump version | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| set -euo pipefail | ||
| TAG="m$VERSION" | ||
| ASSETS=$(gh release view "$TAG" -R "$SOURCE_REPO" --json assets --jq '.assets[].name') | ||
| for f in libwebrtc.aar libwebrtc_prefixed.aar libwebrtc_prefixed_stripped.aar; do | ||
| for a in "$f" "$f.shasum"; do | ||
| grep -qx "$a" <<< "$ASSETS" || { echo "::error::$a missing from $SOURCE_REPO $TAG"; exit 1; } | ||
| done | ||
| done | ||
| # Built-from commit: first commit link in the release notes. | ||
| NOTES=$(gh release view "$TAG" -R "$SOURCE_REPO" --json body --jq .body) | ||
| COMMIT=$(grep -oE '/commit/[0-9a-f]{40}' <<< "$NOTES" | head -1 | cut -d/ -f3 || true) | ||
| WEBRTC_REPO=$(grep -oE 'https://github.com/[^/]+/[^/]+/commit/' <<< "$NOTES" | head -1 | cut -d/ -f4,5 || true) | ||
| python3 .github/scripts/prepare_release.py --version "$VERSION" --commit "$COMMIT" \ | ||
| --webrtc-repo "${WEBRTC_REPO:-webrtc-sdk/webrtc}" | ||
| { | ||
| echo "Release WebRTC Android SDK $VERSION." | ||
| echo | ||
| echo "Binaries: [$SOURCE_REPO $TAG](https://github.com/$SOURCE_REPO/releases/tag/$TAG) (\`libwebrtc.aar\`, \`libwebrtc_prefixed.aar\`, \`libwebrtc_prefixed_stripped.aar\`)." | ||
| echo | ||
| echo "Merging publishes the GitHub release v$VERSION and the Maven artifacts." | ||
| echo | ||
| echo '<details><summary>webrtc changes</summary>' | ||
| echo | ||
| echo "$NOTES" | ||
| echo | ||
| echo '</details>' | ||
| } > "$RUNNER_TEMP/body.md" | ||
| - uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| token: ${{ steps.app.outputs.token || github.token }} | ||
| branch: release/${{ env.VERSION }} | ||
| commit-message: 'release: ${{ env.VERSION }}' | ||
| title: 'release: ${{ env.VERSION }}' | ||
| body-path: ${{ runner.temp }}/body.md | ||
| labels: release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| name: release | ||
|
|
||
| # Runs when a release/<version> PR is merged: downloads the three aars and | ||
| # their .shasum files from the webrtc-build release m<version>, verifies them, | ||
| # publishes them as this repository's release v<version>, then runs | ||
| # publish.yml (Maven Central), which downloads them from that release. | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: [main] | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: 'Version to (re)publish from the default branch' | ||
| required: true | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| concurrency: | ||
| group: release | ||
| cancel-in-progress: false | ||
|
cloudwebrtc marked this conversation as resolved.
Resolved
|
||
| # Queue every waiting release: by default a newer run cancels the pending | ||
| # one, which would leave that merged release unpublished. | ||
| queue: max | ||
|
|
||
| env: | ||
| SOURCE_REPO: ${{ vars.SOURCE_REPO || 'webrtc-sdk/webrtc-build' }} | ||
|
|
||
| jobs: | ||
| github-release: | ||
| if: >- | ||
| github.event_name == 'workflow_dispatch' || | ||
| (github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/')) | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| ref: ${{ steps.v.outputs.ref }} | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| ref: ${{ github.event.pull_request.merge_commit_sha || github.sha }} | ||
| - name: Version | ||
| id: v | ||
| env: | ||
| INPUT: ${{ inputs.version || github.event.pull_request.head.ref }} | ||
| run: | | ||
| set -euo pipefail | ||
| VERSION="${INPUT#release/}" | ||
| PROP=$(sed -n 's/^VERSION_NAME=//p' gradle.properties) | ||
| [ "$PROP" = "$VERSION" ] || { echo "::error::VERSION_NAME $PROP != $VERSION"; exit 1; } | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "ref=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" | ||
| - name: Download and verify aars | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| VERSION: ${{ steps.v.outputs.version }} | ||
| run: | | ||
| set -euo pipefail | ||
| mkdir -p dist && cd dist | ||
| for f in libwebrtc.aar libwebrtc_prefixed.aar libwebrtc_prefixed_stripped.aar; do | ||
| gh release download "m$VERSION" -R "$SOURCE_REPO" -p "$f" -p "$f.shasum" | ||
| done | ||
| shasum -a 256 -c *.shasum | ||
| - name: Create release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| VERSION: ${{ steps.v.outputs.version }} | ||
| run: | | ||
| set -euo pipefail | ||
| { | ||
| echo "WebRTC Android SDK $VERSION, built by [$SOURCE_REPO m$VERSION](https://github.com/$SOURCE_REPO/releases/tag/m$VERSION)." | ||
| echo | ||
| gh release view "m$VERSION" -R "$SOURCE_REPO" --json body --jq .body | ||
| } > "$RUNNER_TEMP/notes.md" | ||
| if gh release view "v$VERSION" >/dev/null 2>&1; then | ||
| gh release upload "v$VERSION" dist/* --clobber | ||
| else | ||
| gh release create "v$VERSION" dist/* --target "${{ steps.v.outputs.ref }}" --title "v$VERSION" --notes-file "$RUNNER_TEMP/notes.md" | ||
| fi | ||
|
|
||
| publish: | ||
| needs: github-release | ||
| uses: ./.github/workflows/publish.yml | ||
| with: | ||
| ref: ${{ needs.github-release.outputs.ref }} | ||
| secrets: inherit | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.