diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f2fa520bb39..bce40830761a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,18 +8,27 @@ on: - labeled jobs: - check_actor: - name: Check release actor + check_pr: + name: Check PR runs-on: ubuntu-latest steps: - - if: github.actor != github.repository_owner - run: exit 1 + - name: Check release actor + if: github.actor != github.repository_owner + run: | + echo "::error::Only repository owner can create releases." + exit 1 + + - name: Check release label + if: github.event.label.name != 'release' + run: | + echo "::error::You need to specify the 'release' label to create releases." + exit 1 get_new_version: name: Get new version runs-on: ubuntu-latest needs: - - check_actor + - check_pr outputs: version: ${{ steps.new_version.outputs.NEW_VERSION }} steps: @@ -29,29 +38,27 @@ jobs: fetch-depth: 0 - name: Get latest tag - id: latest_tag run: | git fetch --prune 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 ${{ github.workspace }}/package.json '.version' | cut -d '-' -f 1)" >> $GITHUB_ENV + - name: Get prev base version + run: echo "PREV_BASE_VERSION=$(echo ${{ env.LATEST_TAG }} | cut -d- -f1)" >> $GITHUB_ENV + + - name: Get next base version + run: echo "NEXT_BASE_VERSION=$(jq -r '${{ github.workspace }}/package.json' '.version' | cut -d- -f1)" >> $GITHUB_ENV - name: Reset revision - if: github.env.PREV_BASE_VERSION != github.env.NEXT_BASE_VERSION + if: env.PREV_BASE_VERSION != 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 + if: env.PREV_BASE_VERSION == env.NEXT_BASE_VERSION + run: echo "REVISION=$(($(echo ${{ env.LATEST_TAG }} | cut -d- -f2 | cut -d. -f2) + 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 + run: echo "NEW_VERSION=${{ env.NEXT_BASE_VERSION }}-taiyme.${{ env.REVISION }}" >> $GITHUB_OUTPUT update_package_json: name: Update package.json @@ -63,7 +70,7 @@ jobs: 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" + 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 @@ -71,8 +78,26 @@ jobs: name: version_files path: ${{ github.workspace }}/package.json + update_package_json_misskey_js: + name: Update package.json (misskey-js) + runs-on: ubuntu-latest + needs: + - get_new_version + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Update package.json (misskey-js) + run: jq ".version = '${{ needs.get_new_version.outputs.version }}'" "${{ github.workspace }}/packages/misskey-js/package.json" --tab > tmp && mv tmp "${{ github.workspace }}/packages/misskey-js/package.json" + + - name: Upload package.json (misskey-js) + uses: actions/upload-artifact@v3 + with: + name: version_files + path: ${{ github.workspace }}/packages/misskey-js/package.json + update_docker_compose_yml: - name: Update docker-compose.yml + name: Update compose.yml runs-on: ubuntu-latest needs: - get_new_version @@ -80,20 +105,21 @@ jobs: - 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: Update compose.yml + run: yq -r eval ".services.web.image = 'ghcr.io/${{ github.repository }}:${{ needs.get_new_version.outputs.version }}'" -i "${{ github.workspace }}/compose_example.yml" - - name: Upload docker-compose.yml + - name: Upload compose.yml uses: actions/upload-artifact@v3 with: name: version_files - path: ${{ github.workspace }}/docker-compose_example.yml + path: ${{ github.workspace }}/compose_example.yml commit_tag_push: name: Commit, Tag and Push needs: - get_new_version - update_package_json + - update_package_json_misskey_js - update_docker_compose_yml runs-on: ubuntu-latest steps: @@ -117,12 +143,12 @@ jobs: 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 commit --author=. -m "Release: ${{ 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 + name: Merge PR needs: - commit_tag_push runs-on: ubuntu-latest @@ -130,7 +156,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: merge PR + - name: Merge PR env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: |