Release #35
This file contains 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
name: Release | |
on: | |
workflow_dispatch: | |
inputs: | |
base_version: | |
type: string | |
description: Enter base version. (e.g. 2024.8.0) | |
required: true | |
default: "" | |
concurrency: | |
group: release | |
cancel-in-progress: false | |
permissions: | |
contents: read | |
jobs: | |
check-context: | |
name: Check context | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Check actor | |
if: github.actor != github.repository_owner | |
run: exit 1 | |
- name: Check branch | |
if: github.ref_name != vars.DEVELOP_BRANCH | |
run: exit 1 | |
- name: Check base version | |
env: | |
base_version: ${{ inputs.base_version }} | |
run: | | |
if [[ -z "$base_version" ]]; then | |
exit 1 | |
fi | |
year="$(cut -d. -f1 <<< "$base_version")" | |
if [[ ! "$year" =~ ^[0-9]+$ ]]; then | |
exit 1 | |
fi | |
month="$(cut -d. -f2 <<< "$base_version")" | |
if [[ ! "$month" =~ ^[0-9]+$ ]] || \ | |
[[ "$month" -lt 1 || "$month" -gt 12 ]]; then | |
exit 1 | |
fi | |
patch="$(cut -d. -f3 <<< "$base_version")" | |
if [[ ! "$patch" =~ ^[0-9]+$ ]]; then | |
exit 1 | |
fi | |
parse-version: | |
name: Parse new version | |
runs-on: ubuntu-22.04 | |
needs: | |
- check-context | |
outputs: | |
new_version: ${{ steps.generate.outputs.new_version }} | |
steps: | |
- name: Checkout ${{ github.sha }} | |
uses: actions/[email protected] | |
with: | |
persist-credentials: false | |
ref: ${{ github.sha }} | |
fetch-depth: 1 | |
- name: Generate new version | |
id: generate | |
env: | |
base_version: ${{ inputs.base_version }} | |
run: | | |
current_version="$(cat package.json | jq -r '.version')" | |
current_base="$(sed 's/-.*//' <<< "$current_version")" | |
new_base="${base_version:-"$current_base"}" | |
if [[ "$current_version" != "$current_base" && \ | |
"$current_base" == "$new_base" ]]; then | |
current_suffix="$((cut -d- -f2 | cut -d. -f2) <<< "$current_version")" | |
new_suffix="$(("$current_suffix" + 1))" | |
fi | |
new_suffix="${new_suffix:-0}" | |
new_version="${new_base}-taiyme.${new_suffix}" | |
echo "new_version=${new_version}" >> $GITHUB_OUTPUT | |
bump-version-update: | |
name: Bump version (update) | |
runs-on: ubuntu-22.04 | |
needs: | |
- parse-version | |
steps: | |
- name: Checkout ${{ github.sha }} | |
uses: actions/[email protected] | |
with: | |
persist-credentials: false | |
ref: ${{ github.sha }} | |
fetch-depth: 1 | |
- name: Update package.json (root) | |
run: | | |
jq --tab '.version = "${{ needs.parse-version.outputs.new_version }}"' package.json > tmp | |
mv tmp package.json | |
- name: Update package.json (misskey-js) | |
working-directory: packages/misskey-js | |
run: | | |
jq --tab '.version = "${{ needs.parse-version.outputs.new_version }}"' package.json > tmp | |
mv tmp package.json | |
- name: Update compose_example.yml | |
run: | | |
old_docker_image="$(yq '.services.web.image' compose_example.yml)" | |
new_docker_image='${{ vars.DOCKER_IMAGE_NAME }}:${{ needs.parse-version.outputs.new_version }}' | |
sed -i "s|image: ${old_docker_image}|image: ${new_docker_image}|g" compose_example.yml | |
- name: Upload artifacts | |
uses: actions/[email protected] | |
with: | |
name: bump_version_files | |
path: | | |
package.json | |
packages/misskey-js/package.json | |
compose_example.yml | |
bump-version-upload: | |
name: Bump version (upload) | |
runs-on: ubuntu-22.04 | |
needs: | |
- parse-version | |
- bump-version-update | |
steps: | |
- name: Create GitHub App Token | |
uses: actions/[email protected] | |
id: app-token | |
with: | |
app-id: ${{ secrets.RELEASE_APP_ID }} | |
private-key: ${{ secrets.RELEASE_PRIVATE_KEY }} | |
- name: Get GitHub App User ID | |
id: get-user-id | |
env: | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
run: | | |
user_id="$(gh api '/users/${{ steps.app-token.outputs.app-slug }}[bot]' --jq '.id')" | |
echo "user-id=${user_id}" >> $GITHUB_OUTPUT | |
- name: Checkout ${{ vars.DEVELOP_BRANCH }} | |
uses: actions/[email protected] | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
persist-credentials: false | |
ref: ${{ vars.DEVELOP_BRANCH }} | |
fetch-depth: 1 | |
- name: Download artifacts | |
uses: actions/[email protected] | |
with: | |
name: bump_version_files | |
- name: Commit and Push | |
run: | | |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' | |
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' | |
git remote set-url origin https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ github.repository }} | |
git add . | |
git commit -m 'Release: ${{ needs.parse-version.outputs.new_version }}' | |
git tag ${{ needs.parse-version.outputs.new_version }} | |
git push origin HEAD | |
git push origin ${{ needs.parse-version.outputs.new_version }} | |
create-pr: | |
name: Create PR | |
runs-on: ubuntu-22.04 | |
needs: | |
- parse-version | |
- bump-version-upload | |
outputs: | |
pr_number: ${{ steps.create-pr.outputs.pr_number }} | |
steps: | |
- name: Create GitHub App Token | |
uses: actions/[email protected] | |
id: app-token | |
with: | |
app-id: ${{ secrets.RELEASE_APP_ID }} | |
private-key: ${{ secrets.RELEASE_PRIVATE_KEY }} | |
- name: Checkout ${{ vars.DEVELOP_BRANCH }} | |
uses: actions/[email protected] | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
persist-credentials: false | |
ref: ${{ vars.DEVELOP_BRANCH }} | |
fetch-depth: 0 | |
- name: Create PR | |
id: create-pr | |
env: | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
run: | | |
created_pr="$( | |
gh pr create --draft \ | |
--base ${{ vars.RELEASE_BRANCH }} \ | |
--head ${{ vars.DEVELOP_BRANCH }} \ | |
--title 'Release: ${{ needs.parse-version.outputs.new_version }}' \ | |
--body '' | |
)" | |
pr_number="$(awk -F '/' '/\/pull\/[0-9]+$/ {print $NF}' <<< "$created_pr")" | |
echo "pr_number=${pr_number}" >> $GITHUB_OUTPUT | |
merge-pr: | |
name: Merge PR | |
runs-on: ubuntu-22.04 | |
needs: | |
- create-pr | |
steps: | |
- name: Create GitHub App Token | |
uses: actions/[email protected] | |
id: app-token | |
with: | |
app-id: ${{ secrets.RELEASE_APP_ID }} | |
private-key: ${{ secrets.RELEASE_PRIVATE_KEY }} | |
- name: Checkout ${{ vars.DEVELOP_BRANCH }} | |
uses: actions/[email protected] | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
persist-credentials: false | |
ref: ${{ vars.DEVELOP_BRANCH }} | |
fetch-depth: 1 | |
- name: Merge PR | |
env: | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
run: | | |
gh pr checks ${{ needs.create-pr.outputs.pr_number }} --watch | |
gh pr ready ${{ needs.create-pr.outputs.pr_number }} | |
gh pr merge ${{ needs.create-pr.outputs.pr_number }} --merge --auto | |
release: | |
name: Release | |
runs-on: ubuntu-22.04 | |
needs: | |
- parse-version | |
- merge-pr | |
steps: | |
- name: Create GitHub App Token | |
uses: actions/[email protected] | |
id: app-token | |
with: | |
app-id: ${{ secrets.RELEASE_APP_ID }} | |
private-key: ${{ secrets.RELEASE_PRIVATE_KEY }} | |
- name: Checkout ${{ vars.RELEASE_BRANCH }} | |
uses: actions/[email protected] | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
persist-credentials: false | |
ref: ${{ vars.RELEASE_BRANCH }} | |
fetch-depth: 0 | |
- name: Generate release notes | |
id: generate-release-notes | |
uses: ./.github/actions/generate-release-notes | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
version: ${{ needs.parse-version.outputs.new_version }} | |
- name: Set release notes | |
env: | |
release_notes: ${{ steps.generate-release-notes.outputs.release_notes }} | |
run: | | |
echo "$release_notes" > /tmp/release-notes.md | |
- name: Create Release | |
env: | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
run: | | |
gh release create ${{ needs.parse-version.outputs.new_version }} \ | |
--title ${{ needs.parse-version.outputs.new_version }} \ | |
--notes-file /tmp/release-notes.md |