Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GitHub Actions活用術

Wataru Mizukami
October 28, 2020
710

GitHub Actions活用術

Wataru Mizukami

October 28, 2020
Tweet

Transcript

  1. 自己紹介 - Wataru Mizukami / 水上 亘 -         / @tarumzu

    (たる) - Organization / タクシー配車アプリ作ってる会社
  2. GitHub Actionsの設定 name: danger on: pull_request: branches: - master jobs:

    build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: Setup ruby uses: actions/setup-ruby@v1 with: ruby-version: '2.6' architecture: 'x64' - name: install danger run: | gem install bundler bundle install - name: run ktlintCheck run: ./gradlew ktlintCheck - name: run danger env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: danger
  3. GitHub Actionsの設定 name: danger on: pull_request: branches: - master jobs:

    build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: Setup ruby uses: actions/setup-ruby@v1 with: ruby-version: '2.6' architecture: 'x64' - name: install danger run: | gem install bundler bundle install - name: run ktlintCheck run: ./gradlew ktlintCheck - name: run danger env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: danger - name: run danger env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: danger DangerはGitHub Actionsに対応しているので、 GitHubのアクセストークンを環境変数 `GITHUB_TOKEN` として設定してあげるだけで OK! GitHub ActionsはCI実行ごとにデフォルトで secretsにトークンが設定される。
  4. ワークフローの書き方 name: publish // 略 jobs: build: runs-on: ubuntu-latest steps:

    - uses: actions/checkout@v2 // 略 - name: Build with Gradle run: ./gradlew :app:assembleDebug - name: Upload apk uses: actions/upload-artifact@v2 with: name: apk path: app/build/outputs/apk publish: needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Download apk uses: actions/download-artifact@v2 with: name: apk // 略
  5. ワークフローの書き方 name: publish // 略 jobs: build: runs-on: ubuntu-latest steps:

    - uses: actions/checkout@v2 // 略 - name: Build with Gradle run: ./gradlew :app:assembleDebug - name: Upload apk uses: actions/upload-artifact@v2 with: name: apk path: app/build/outputs/apk publish: needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Download apk uses: actions/download-artifact@v2 with: name: apk // 略 publish: needs: build タスクごとにJobを分けるとワークフローが見やす い。この例だとbuild, publishと分けている(実際に は他にtestやdangerなども)。 jobは基本的に並列で動きますが、特定のジョブ の結果を待ちたい場合、needsでジョブを指定する ことで直列にすることもできる。
  6. ワークフローの書き方 name: publish // 略 jobs: build: runs-on: ubuntu-latest steps:

    - uses: actions/checkout@v2 // 略 - name: Build with Gradle run: ./gradlew :app:assembleDebug - name: Upload apk uses: actions/upload-artifact@v2 with: name: apk path: app/build/outputs/apk publish: needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Download apk uses: actions/download-artifact@v2 with: name: apk // 略 - name: Upload apk uses: actions/upload-artifact@v2 with: name: apk path: app/build/outputs/apk ジョブ間でファイルの受け渡しをする場合、 upload-artifactアクションが必要。
  7. ワークフローの書き方 name: publish // 略 jobs: build: runs-on: ubuntu-latest steps:

    - uses: actions/checkout@v2 // 略 - name: Build with Gradle run: ./gradlew :app:assembleDebug - name: Upload apk uses: actions/upload-artifact@v2 with: name: apk path: app/build/outputs/apk publish: needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Download apk uses: actions/download-artifact@v2 with: name: apk // 略 - name: Download apk uses: actions/download-artifact@v2 with: name: apk 受け取り側はdownload-artifactでファイルを受け 取る
  8. Github Actions (v2) でDanger + ktlintを実行させる https://qiita.com/tarumzu/items/43 2fc356580ebfab77d4 GitHub Actionsを使ってAndroidア

    プリをFirebase App Distributionへ 配信するまでのベストプラクティス
 https://qiita.com/tarumzu/items/43 2fc356580ebfab77d4