Skip to content

Commit

Permalink
GitHub Actionsによるリリースの自動化 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
cffnpwr authored Mar 1, 2023
1 parent c42e4e7 commit 6e9bca5
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ insert_final_newline = true

[*.yml]
indent_style = space

[*.yaml]
indent_style = space
25 changes: 22 additions & 3 deletions .github/workflows/docker.yml → .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Publish Docker image

on:
release:
types: [published]
workflow_dispatch:
workflow_call:
inputs:
tag:
required: true
type: string

jobs:
build_and_push:
Expand All @@ -12,11 +15,26 @@ jobs:
strategy:
matrix:
arch: [arm64, amd64]
outputs:
latest-tag: ${{ steps.latest-tag.outputs.latest-tag }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get latest tag
id: latest-tag
if: github.event_name == 'workflow_dispatch'
run: |
git fetch --prune --unshallow
echo "latest-tag=$(git describe --tags --abbrev=0)"
- name: Checkout latest tag
if: github.event_name == 'workflow_dispatch'
uses: actions/checkout@v3
with:
ref: ${{ steps.latest-tag.outputs.latest-tag }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

Expand Down Expand Up @@ -63,7 +81,8 @@ jobs:
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=tag,enable=${{ github.event_name != 'workflow_dispatch' }}
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name != 'workflow_dispatch' }}
type=raw,value=${{ needs.build_and_push.outputs.latest-tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
type=raw,value=latest
- name: Convert tags
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/docker/Dockerfile.amd64
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
FROM node:18.14.1-bullseye AS common

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get install -y --no-install-recommends build-essential
RUN apt-get update
RUN apt-get install -y --no-install-recommends build-essential


FROM common AS builder
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/docker/Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ RUN \
export OBJDUMP="aarch64-linux-gnu-objdump" && \
export NM="aarch64-linux-gnu-nm" && \
export AS="aarch64-linux-gnu-as"
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get install -y --no-install-recommends build-essential g++-aarch64-linux-gnu jq
RUN apt-get update
RUN apt-get install -y --no-install-recommends build-essential g++-aarch64-linux-gnu jq


FROM --platform=linux/amd64 common AS re2
Expand Down
189 changes: 189 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
name: Release
on:
pull_request:
branches:
- release
types:
- labeled

jobs:
check_label:
name: Check release label
runs-on: ubuntu-latest
steps:
- name: Check PR actor
if: github.actor != github.repository_owner
run: exit 1

- name: Throw an error if PR has no release tags
if: github.event.label.name != 'release-patch' && github.event.label.name != 'release-patch' && github.event.label.name != 'release-patch'
run: |
echo "::error::PR has no release tags!! (release-major, release-minor, release-patch)"
exit 1
get_diff:
name: Get diff
runs-on: ubuntu-latest
needs: [check_label]
outputs:
package_diff: ${{ steps.get_diff.outputs.package_diff }}
compose_diff: ${{ steps.get_diff.outputs.compose_diff }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get release branch
run: git fetch origin ${{ github.base_ref }} --depth 1

- name: Get diff
id: get_diff
run: |
echo "package_diff=$(git diff origin/${{ github.base_ref }} HEAD --relative "./package.json" | grep "^+.\+version" | wc -l)" >> $GITHUB_OUTPUT
echo "compose_diff=$(git diff origin/${{ github.base_ref }} HEAD --relative "./docker-compose.yml" | grep "^+.\+image" | wc -l)" >> $GITHUB_OUTPUT
update_version:
name: Update version
runs-on: ubuntu-latest
needs: [get_diff]
outputs:
version: ${{ steps.version.outputs.result }}
steps:
- name: Check if updates are needed
if: needs.get_diff.outputs.package_diff != '0' && needs.get_diff.outputs.compose_diff != '0'
run: exit 0

- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Update package.json
uses: actions/github-script@v6
id: version
with:
result-encoding: string
script: |
const fs = require('fs')
const json = JSON.parse(fs.readFileSync('${{ github.workspace }}/package.json'))
let version = json.version
if (${{ needs.get_diff.outputs.package_diff == '0' }}) {
const isPatch = ${{ github.event.label.name == 'release-patch' }}
const isMinor = ${{ github.event.label.name == 'release-minor' }}
const isMajor = ${{ github.event.label.name == 'release-major' }}
const versionSplit = version.split('-taiyme-v')
const versionMMP = versionSplit[1].split('.')
if (isPatch)
versionMMP[2] = Number(versionMMP[2]) + 1;
if (isMinor) {
versionMMP[1] = Number(versionMMP[1]) + 1;
versionMMP[2] = 0;
}
if (isMajor) {
versionMMP[0] = Number(versionMMP[0]) + 1;
versionMMP[1] = 0;
versionMMP[2] = 0;
}
versionSplit[1] = versionMMP.join('.');
version = versionSplit.join('-taiyme-v')
json.version = version
fs.writeFileSync('${{ github.workspace }}/package.json', JSON.stringify(json, null, '\t'))
}
return version
- name: Update docker-compose.yml
if: needs.get_diff.outputs.compose_diff == '0'
run: |
yq -r eval '.services.web.image = "ghcr.io/${{ github.repository }}:${{ steps.version.outputs.result }}"' -i "${{ github.workspace }}/docker-compose.yml"
- name: Commit and Push
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add .
git commit --author=. -m "${{ steps.version.outputs.result }}"
git push
docker_build:
name: Build Docker image and Push to Github Container Registry
needs: [update_version]
uses: ./.github/workflows/docker.yaml
with:
tag: ${{ needs.update_version.outputs.version }}

release:
name: Release
needs: [update_version, docker_build]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Get changelog title
id: get_changelog_title
run: echo "changelog_title=${{ needs.update_version.outputs.version }} ($(date "+%Y/%m/%d"))" >> $GITHUB_OUTPUT

- name: Get changelog body
id: get_changelog_body
uses: actions/github-script@v6
with:
result-encoding: string
script: return `${{ github.event.pull_request.body }}`

- name: Add new changelog
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const fs = require('fs')
const changelog = fs.readFileSync('${{ github.workspace }}/CHANGELOG.md').toString()
const changelogSplit = changelog.split('-->\n\n##')
const changelogAdded = `## ${{ steps.get_changelog_title.outputs.changelog_title }}\n\n${{ steps.get_changelog_body.outputs.result }}\n\n`
const chnagelogArray = [changelogSplit[0] + "-->\n\n", changelogAdded, "##" + changelogSplit[1]]
const newChangelog = chnagelogArray.join('')
fs.writeFileSync('${{ github.workspace }}/CHANGELOG.md', newChangelog)
- name: Commit and Push
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add .
git commit --author=. -m "update CHANGELOG.md"
git push
- name: merge PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge ${{ github.event.pull_request.number }} --merge

- name: Checkout release branch
uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}

- name: Commit and Push
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag "${{ needs.update_version.outputs.version }}"
git push --tags
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.update_version.outputs.version }}
body: ${{ steps.get_changelog_body.outputs.result }}
5 changes: 1 addition & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ version: "3"

services:
web:
build:
context: .
cache_from:
- ghcr.io/taiyme/misskey:buildcache
image: ghcr.io/taiyme/misskey:12.119.2-taiyme-v1.0.40
restart: always
ports:
- 3000:3000
Expand Down
22 changes: 22 additions & 0 deletions docs/how-to-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# taiyme/misskeyのリリース手順

## Pull Requestの作成

`release`ブランチに対するPRを作成する。
このとき、PRの本文にチェンジログを書く。
タイトルは影響しない。

## Pull Requestにラベルを付与

作成したPRに`release-major`, `release-minor`, `release-patch`のいずれかのラベルを付与する。
被せて付与することも可能だが、最上位のバージョン更新のみが適用される。

## Github Actionsの完了を待つ

待ちましょう。
Githubに障害等がなければ10分程度で終わる。

## リリース完了

リリース完了。
`https://github.com/taiyme/misskey/releases/latest`から最新のリリースを確認できる。
26 changes: 19 additions & 7 deletions docs/install-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## リポジトリの取得

```sh
git clone -b taiyme-v12 https://github.com/taiyme/misskey.git
git clone -b release https://github.com/taiyme/misskey.git
cd misskey
```

Expand All @@ -28,21 +28,33 @@ cp .config/docker_example.env .config/docker.env

## 起動

お疲れ様でした。以下のコマンドでMisskeyをビルドして起動できます
お疲れ様でした。以下のコマンドでMisskeyをPullして起動できます
ご使用のインターネット環境によっては時間がかかることがあります。

```sh
export COMPOSE_DOCKER_CLI_BUILD=1
docker compose up -d --build
docker compose up -d
```

## Misskeyのアップデート方法

```sh
git stash
git checkout taiyme-v12
git checkout release
git pull
git stash pop
export COMPOSE_DOCKER_CLI_BUILD=1
docker compose up -d --build
docker compose up -d
```

## 特定のバージョンのMisskeyへの切り替え

最新のリリースに不具合がある場合などは以下の手順でバージョンを切り替えられます。
`[version]`に切り替えたいバージョンを入力してください。
バージョン一覧は[ここ](https://github.com/taiyme/misskey/releases)から確認できます。

```sh
git stash
git checkout [version]
git pull
git stash pop
docker compose up -d
```

0 comments on commit 6e9bca5

Please sign in to comment.