|
| 1 | +name: Create a release pull request |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + versionMajor: |
| 7 | + description: "バージョン情報: major" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + versionMinor: |
| 11 | + description: "バージョン情報: minor" |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + versionPatch: |
| 15 | + description: "バージョン情報: patch" |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }} |
| 21 | + cancel-in-progress: true |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + if: ${{ github.ref_type == 'branch' && github.ref_name == 'develop' }} |
| 26 | + runs-on: ubuntu-24.04 |
| 27 | + outputs: |
| 28 | + branch: ${{ steps.meta.outputs.branch }} |
| 29 | + version: ${{ steps.meta.outputs.version }} |
| 30 | + permissions: |
| 31 | + contents: write |
| 32 | + timeout-minutes: 5 |
| 33 | + steps: |
| 34 | + # https://github.com/actions/checkout |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + |
| 37 | + # https://github.com/actions/setup-node |
| 38 | + - uses: actions/setup-node@v4 |
| 39 | + with: |
| 40 | + node-version-file: .node-version |
| 41 | + cache: npm |
| 42 | + cache-dependency-path: ./package-lock.json |
| 43 | + |
| 44 | + - name: Set version & format branch name |
| 45 | + id: meta |
| 46 | + env: |
| 47 | + VERSION: "${{ inputs.versionMajor }}.${{ inputs.versionMinor }}.${{ inputs.versionPatch }}" |
| 48 | + run: | |
| 49 | + npm version "$VERSION" --no-git-tag-version |
| 50 | + version=$(node -p "require('./package.json').version") |
| 51 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 52 | + echo "branch=feature/$version" >> "$GITHUB_OUTPUT" |
| 53 | +
|
| 54 | + - name: Can release |
| 55 | + env: |
| 56 | + GH_TOKEN: ${{ github.token }} |
| 57 | + TAG: ${{ steps.meta.outputs.version }} |
| 58 | + run: bash .github/scripts/can-release.bash "$TAG" |
| 59 | + |
| 60 | + - run: npm ci |
| 61 | + |
| 62 | + - run: npm test |
| 63 | + |
| 64 | + - run: npm run build |
| 65 | + |
| 66 | + # https://github.com/actions/checkout/issues/13#issuecomment-724415212 |
| 67 | + - name: Set up git user |
| 68 | + run: | |
| 69 | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 70 | + git config --local user.name "github-actions[bot]" |
| 71 | +
|
| 72 | + - name: git add & push |
| 73 | + env: |
| 74 | + BRANCH: ${{ steps.meta.outputs.branch }} |
| 75 | + VERSION: ${{ steps.meta.outputs.version }} |
| 76 | + run: | |
| 77 | + git switch --create "$BRANCH" |
| 78 | + git add compiled |
| 79 | + git add package.json |
| 80 | + git add package-lock.json |
| 81 | + git commit --message "Update $VERSION" |
| 82 | + git push --set-upstream origin "$BRANCH" |
| 83 | +
|
| 84 | +
|
| 85 | + test-action: |
| 86 | + needs: build |
| 87 | + uses: ./.github/workflows/test-action.yml |
| 88 | + with: |
| 89 | + git_ref: ${{ needs.build.outputs.branch }} |
| 90 | + |
| 91 | + |
| 92 | + create-pr: |
| 93 | + needs: |
| 94 | + - build |
| 95 | + - test-action |
| 96 | + runs-on: ubuntu-24.04 |
| 97 | + permissions: |
| 98 | + contents: write |
| 99 | + pull-requests: write |
| 100 | + timeout-minutes: 5 |
| 101 | + steps: |
| 102 | + # https://github.com/actions/checkout |
| 103 | + - uses: actions/checkout@v4 |
| 104 | + with: |
| 105 | + ref: ${{ needs.build.outputs.branch }} |
| 106 | + |
| 107 | + - name: Generate diff notes |
| 108 | + id: notes |
| 109 | + env: |
| 110 | + GH_TOKEN: ${{ github.token }} |
| 111 | + REF_NAME: ${{ needs.build.outputs.branch }} |
| 112 | + TAG: ${{ needs.build.outputs.version }} |
| 113 | + run: | |
| 114 | + response=$(bash .github/scripts/presume-release-notes.bash "$TAG" "$REF_NAME") |
| 115 | + echo "response=$response" >> "$GITHUB_OUTPUT" |
| 116 | + echo "$response" |
| 117 | +
|
| 118 | + - name: Create a file for pull request body |
| 119 | + shell: ruby {0} |
| 120 | + env: |
| 121 | + NOTE: ${{ fromJson(steps.notes.outputs.response).body }} |
| 122 | + URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 123 | + run: | |
| 124 | + text = <<"BODY" |
| 125 | + Test result: #{ENV['URL']} |
| 126 | +
|
| 127 | + #{ENV['NOTE']} |
| 128 | + BODY |
| 129 | + File.open("PR_BODY", "w") { |file| |
| 130 | + file.write(text) |
| 131 | + } |
| 132 | +
|
| 133 | + - name: Create a pull request |
| 134 | + env: |
| 135 | + ASSIGNEE: tshion |
| 136 | + BASE: released |
| 137 | + GH_TOKEN: ${{ github.token }} |
| 138 | + TITLE: "Update ${{ needs.build.outputs.version }}" |
| 139 | + run: gh pr create --assignee "$ASSIGNEE" --base "$BASE" --title "$TITLE" --body-file PR_BODY |
0 commit comments