Skip to content
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

Rework release workflow #38

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Create release PR
on:
workflow_dispatch:
inputs:
version:
description: 'New version'
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
strategy:
matrix:
node-version: [20]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Create app token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.THEOPLAYER_BOT_APP_ID }}
private-key: ${{ secrets.THEOPLAYER_BOT_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Configure Git user
run: |
git config user.name 'theoplayer-bot[bot]'
git config user.email '873105+theoplayer-bot[bot]@users.noreply.github.com'
- name: Bump version
shell: bash
run: |
node ./scripts/set_version.js ${{ inputs.version }}
- name: Push to release branch
shell: bash
run: |
git commit -a -m ${{ inputs.version }}
git push origin "HEAD:release/${{ inputs.version }}"
- name: Create pull request
shell: bash
run: |
gh pr create \
--base main \
--head "release/${{ inputs.version }}" \
--title "Release ${{ inputs.version }}" \
--body "$(node ./scripts/github_changelog.js ${{ inputs.version }})"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
40 changes: 36 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
name: Publish release
on:
# Runs whenever a new release is created in GitHub
release:
types: [ created ]
# Runs whenever a release PR is merged
pull_request:
branches:
- main
types: [ closed ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
# Publish job
publish:
# Run only for "release/x.y.z" PRs, and only when the PR is merged (not abandoned)
if: ${{ !github.event.pull_request || (startsWith(github.head_ref, 'release/') && github.event.pull_request.merged) }}
runs-on: ubuntu-latest
# Sets permissions of the GITHUB_TOKEN to allow publishing to GitHub Packages
permissions:
contents: read
contents: write
packages: write
id-token: write
steps:
- name: Create app token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.THEOPLAYER_BOT_APP_ID }}
private-key: ${{ secrets.THEOPLAYER_BOT_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Configure Git user
run: |
git config user.name 'theoplayer-bot[bot]'
git config user.email '873105+theoplayer-bot[bot]@users.noreply.github.com'
- name: Setup Java
uses: actions/setup-java@v4
with:
Expand All @@ -32,3 +49,18 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSILITE_USERNAME: ${{ secrets.REPOSILITE_USERNAME }}
REPOSILITE_PASSWORD: ${{ secrets.REPOSILITE_PASSWORD }}
- name: Get version
shell: bash
run: |
echo "version=$(./gradlew :ui:properties --no-daemon --console=plain --quiet | awk '/^version:/ {print $2}')" >> "$GITHUB_ENV"
- name: Push tag
run: |
git tag "v$version" -m "$version"
git push origin "v$version"
- name: Create GitHub release
run: |
gh release create "v$version" --verify-tag --latest \
--title "$version" \
--notes "$(node ./scripts/github_changelog.js $version)"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
31 changes: 31 additions & 0 deletions .github/workflows/sync-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Sync develop with main
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Create app token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.THEOPLAYER_BOT_APP_ID }}
private-key: ${{ secrets.THEOPLAYER_BOT_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
ref: develop
fetch-depth: 50
- name: Configure Git user
run: |
git config user.name 'theoplayer-bot[bot]'
git config user.email '873105+theoplayer-bot[bot]@users.noreply.github.com'
- name: Sync develop with main
run: |
git fetch --no-tags --prune --no-recurse-submodules --depth=50 origin +refs/heads/main:refs/remotes/origin/main
git merge --ff origin/main
git push origin HEAD:develop
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ android.nonTransitiveRClass=true
android.nonFinalResIds=true
org.gradle.configuration-cache=true
# The version of the THEOplayer Open Video UI for Android.
libraryVersion=1.8.0
version=1.8.0
23 changes: 23 additions & 0 deletions scripts/github_changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env node
const fs = require("node:fs");
const path = require("node:path");
const version = process.argv[2];
if (!version) {
console.error("Missing required argument: version");
process.exit(1);
}

// Find block with current version
const changelogPath = path.resolve(__dirname, "../CHANGELOG.md");
const changelog = fs.readFileSync(changelogPath, "utf-8");
const headingStart = "## ";
// Find block with current version
const block = changelog
.split(headingStart)
.find((block) => block.startsWith(`v${version}`))
.trim();
let lines = block.split("\n");
// Remove version
lines.splice(0, 1);

console.log(lines.join("\n").trim());
30 changes: 30 additions & 0 deletions scripts/set_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env node
const fs = require("node:fs");
const path = require("node:path");
const version = process.argv[2];
if (!version) {
console.error("Missing required argument: version");
process.exit(1);
}

// Update "version=1.2.3" in gradle.properties
const gradlePropertiesPath = path.resolve(__dirname, "../gradle.properties");
let gradleProperties = fs.readFileSync(gradlePropertiesPath, "utf8");
gradleProperties = gradleProperties.replace(
/^version=.+$/m,
`version=${version}`
);
fs.writeFileSync(gradlePropertiesPath, gradleProperties);

// Update heading in CHANGELOG.md
const changelogPath = path.resolve(__dirname, "../CHANGELOG.md");
let changelog = fs.readFileSync(changelogPath, "utf8");
const now = new Date();
const today = `${now.getFullYear()}-${(now.getMonth() + 1)
.toString()
.padStart(2, "0")}-${now.getDate().toString().padStart(2, "0")}`;
changelog = changelog.replace(
/^## Unreleased$/m,
`## ${version} (${today})`
);
fs.writeFileSync(changelogPath, changelog);
3 changes: 1 addition & 2 deletions ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ publishing {

publications {
register<MavenPublication>("release") {
val libraryVersion: String by rootProject.extra
groupId = "com.theoplayer.android-ui"
artifactId = "android-ui"
version = libraryVersion
version = project.version as String
artifact(dokkaJavadocJar)
afterEvaluate {
from(components["release"])
Expand Down