From a6858739568a18568c0542feb48b119cbd5a8a06 Mon Sep 17 00:00:00 2001 From: CaffeinePower Date: Wed, 1 May 2024 15:34:19 +0000 Subject: [PATCH] =?UTF-8?q?add:=20=E3=83=AA=E3=83=AA=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E7=94=A8Workflow=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-release.yml | 6 +- .github/workflows/release.yaml | 155 +++++++++++++++++++++++++++ docker-compose_example.yml | 3 +- 3 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 07e4cbbd5c84..bf4ac095a25d 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -1,9 +1,9 @@ name: Publish Docker image (release) on: - push: - branches: - - taiyme + release: + types: + - published workflow_dispatch: jobs: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000000..0259432ad75b --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,155 @@ +name: Make Release + +on: + pull_request: + branches: + - release + types: + - labeled + +jobs: + check_actor: + name: Check release actor + runs-on: ubuntu-latest + steps: + - if: github.actor != github.repository_owner + run: exit 1 + + get_new_version: + name: Get new version + runs-on: ubuntu-latest + needs: + - check_actor + outputs: + version: ${{ steps.new_version.outputs.NEW_VERSION }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Get latest tag + id: latest_tag + run: | + git fetch --prune --depth=1 + echo "LATEST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + + - name: Get base version + id: base_version + run: | + echo "PREV_BASE_VERSION=$(echo ${{ github.env.LATEST_TAG }} | cut -d- -f1)" >> $GITHUB_ENV + echo "NEXT_BASE_VERSION=$(jq -r package.json '.version' | cut -d '-' -f 1)" >> $GITHUB_ENV + + - name: Reset revision + if: github.env.PREV_BASE_VERSION != github.env.NEXT_BASE_VERSION + run: echo "REVISION=0" >> $GITHUB_ENV + + - name: Update revision + if: github.env.PREV_BASE_VERSION == github.env.NEXT_BASE_VERSION + run: echo "REVISION=$(($(echo ${{ github.env.LATEST_TAG }} | cut -d '-'' -f 2 | cut -d '.' -f 2) + 1))" >> $GITHUB_ENV + + - name: Build new version + id: new_version + run: | + echo "NEW_VERSION=${{ github.env.NEXT_BASE_VERSION }}-taiyme.${{ github.env.REVISION }}" >> $GITHUB_OUTPUT + + update_package_json: + name: Update package.json + runs-on: ubuntu-latest + needs: + - get_new_version + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Update package.json + run: jq '.version = "${{ needs.get_new_version.outputs.version }}"' "${{ github.workspace }}/package.json" --tab > tmp && mv tmp "${{ github.workspace }}/package.json" + + - name: Upload package.json + uses: actions/upload-artifact@v3 + with: + name: version_files + path: ${{ github.workspace }}/package.json + + update_docker_compose_yml: + name: Update docker-compose.yml + runs-on: ubuntu-latest + needs: + - get_new_version + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Update docker-compose.yml + run: yq -r eval '.services.web.image = "ghcr.io/${{ github.repository }}:${{ needs.get_new_version.outputs.version }}"' -i "${{ github.workspace }}/docker-compose_example.yml" + + - name: Upload docker-compose.yml + uses: actions/upload-artifact@v3 + with: + name: version_files + path: ${{ github.workspace }}/docker-compose_example.yml + + commit_tag_push: + name: Commit, Tag and Push + needs: + - get_new_version + - update_package_json + - update_docker_compose_yml + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} + + - name: Download files + uses: actions/download-artifact@v3 + with: + name: version_files + + - name: Check change + id: is_chnage + run: echo "is_change=$(git status -s | wc -l)" >> $GITHUB_OUTPUT + + - name: Commit and Tag + if: steps.is_chnage.outputs.is_change != '0' + 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 "${{ needs.get_new_version.outputs.version }}" + git tag "${{ needs.get_new_version.outputs.version }}" + git push origin HEAD --follow-tags + + merge_pr: + name: Merge Pull request + needs: + - commit_tag_push + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: merge PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + gh pr merge ${{ github.event.pull_request.number }} --merge + + release: + name: Release + needs: + - get_new_version + - merge_pr + runs-on: ubuntu-latest + steps: + - name: Checkout release branch + uses: actions/checkout@v3 + with: + ref: ${{ github.base_ref }} + + - name: Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ needs.get_new_version.outputs.version }} + body: ${{ github.event.pull_request.body }} diff --git a/docker-compose_example.yml b/docker-compose_example.yml index 5cebbe416467..7c1a120ff714 100644 --- a/docker-compose_example.yml +++ b/docker-compose_example.yml @@ -2,7 +2,8 @@ version: "3" services: web: - build: . + # build: . + image: ghcr.io/taiyme/misskey:12.119.2-taiyme-v1.2.0 restart: always links: - db