3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GitHub Action で基本的なことをやるための研究

Posted at

私もついに GitHub Actions をやるときが来た。私は Azure DevOps 好きなのだが、GitHub Action でやった方がよさそうなケースが出てきたのでその調査をする。

やりたいことは単純で、プルリクエスト作成の自動化と、外部からのAction起動だ。
最初の要件はきっと、1. GitHub のボット用のアカウントを使って、ブランチを作り変更して、プッシュする(多分その権限設定)及び、プルリクエストはきっとTOKEN が使えると思うのでそれを使って GitHub の REST API を使うとかそんな感じだろう。

これを読む限りでは、ベースが同じなので、たまにちょっと違うという感じなので、とっつきやすそう。

git の操作を自動化する

最初に bot で使えるE-mailアドレスがあるっぽい。action@github.com のようだ。 `

git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -m "Add URL" -a

みたいだ。他にもあるみたいなのでそちらも試してみたい。

と、、、考えていたが、タスクを使ったらくっそ簡単に出来たw

タスクを使ったら一瞬で出来た

https://github.com/marketplace/actions/create-pull-request
ページに行って詳細見たら一発で終了。ブランチすら作る必要なかったし、クレデンシャルも特に気にする必要なかった。やっぱ、Azure Pipeline と同じくこの Task というか、Actions の仕組み最高。

Build.ID の取得

# This is a basic workflow that is manually triggered

name: Manual workflow

# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
  workflow_dispatch:
    # Inputs the workflow accepts.
    inputs:
      majorVersion:
        # Friendly description to be shown in the UI instead of 'name'
        description: 'Major Version e.g. 3.0'
        required: true
      targetVersion:
        description: 'Target Version e.g. 3.0.151471'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "greet"
  createPR:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
    - uses: actions/checkout@v2
      with:
        ref: main
    - id: createBranch
      run: |
        git config --local user.email "action@github.com"
        git config --local user.name "GitHub Action"
        
        ./update-version.sh ${{ github.event.inputs.majorVersion }} ${{ github.event.inputs.targetVersion }}
        git add .
        git commit -m "Update Version ${{ github.event.inputs.targetVersion }}"
    - name: Create PullRequest
      id: createPullRequest
      uses: peter-evans/create-pull-request@v3
      with:
        title: Update to verison ${{ github.event.inputs.targetVersion }}
        body: |
          - Update ${{ github.event.inputs.majorVesion}} to ${{ github.event.inputs.targetVersion }}
        branch: action/release.${{ github.event.inputs.targetVersion }}
        labels: |
          automated pr
        reviewers: tsuyoshiushio
    - name: Check outputs
      run: |
          echo "Pull Request Number - ${{ steps.createPullRequest.outputs.pull-request-number }}"
          echo "Pull Request URL - ${{ steps.createPullRequest.outputs.pull-request-url }}"          

ブログをするのもはばかられるぐらい簡単だった。明日はアップデートで、RESTAPIのコールやけど、やったことあるから多分すぐ出来そう。

image.png

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?