LoginSignup
21
6

More than 3 years have passed since last update.

[Github Actions] artifactsを使おう!

Posted at

Github Actions には成果物(artifacts)と言って

  • ジョブからジョブに受け渡したいもの
  • 保存しておきたいもの

を Actions 上に保存できる機能があります。

簡単に利用できるので、是非利用して気持ちいいCICDを書きましょう。

使い方

upload-artifactdownload-artifact が marketplace にあるのでこれ以上何もないのですが、参考に例を書いておきます。

sample1: docker-compose のログを保管しておきたい

name: test
on:
  pull_request:
    branches: [ master ]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js 12.18.0
        uses: actions/setup-node@v1
        with:
          node-version: '12.18.0'
      - name: npm ci
        run: npm ci

      - name: Docker set up
        run: |
          docker-compose build
          docker-compose up -d

      - name: npm test
        run: npm run test

      - name: docker logs save 1
        if: ${{ failure() }}
        run: docker-compose logs > ./docker.log

      - name: docker logs save 2
        uses: actions/upload-artifact@v2
        if: failure()
        with:
          name: docker-logs
          path: ./docker.log 

if failure() で失敗したときのログを保存しています。

ちなみに actions の実行結果は消えないので、ログ程度ならそのまま標準出力垂れ流しで十分です。

sample2: build と test で job を分けたい

job間でファイルをやりとりしたい場合ですね。

name: build & test
on:
  pull_request:
    branches: [ master ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js 12.18.0
        uses: actions/setup-node@v1
        with:
          node-version: '12.18.0'
      - name: npm ci
        run: npm ci

      - name: tsc
        run: npm run tsc # ./dist に出力されるとする

      - name: save dist
        uses: actions/upload-artifact@v2
        if: !failure()
        with:
          name: dist
          path: ./dist

  test:
    runs-on: ubuntu-latest
    steps:
      - name: Use Node.js 12.18.0
        uses: actions/setup-node@v1
        with:
          node-version: '12.18.0'
      - name: npm ci
        run: npm ci

      - name: load dist
        uses: actions/download-artifact@v2
        with:
          name: dist

      - name: test
        run: npm run test

こんな場面あるのか...............?

まとめ

画像とかなんでも保存できるらしいのでいい使い方あったら教えてください

21
6
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
21
6