5
2

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 5 years have passed since last update.

Github actionsメモ

Posted at

ブランチをトリガーに

on:
  push:
    branches:
      - master

GitHub Actionsのワークフロー構文 - GitHub ヘルプ

タグをトリガーに

on:
  push:
    tags:
      - v*

GitHub Actionsのワークフロー構文 - GitHub ヘルプ

タグ名を変数として使用

    - name: Set env
      run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})

    - name: Build
      run: make build-image
      env:
        IMAGE_TAG: ${{ env.RELEASE_VERSION }}

continuous integration - Get the current pushed tag in Github Actions - Stack Overflow

GITHUB_REFには refs/tags/v0.0.1 というような値が渡されるため

Slack通知

    - name: Slack Notification
      uses: homoluctus/slatify@master
      if: always()
      with:
        type: ${{ job.status }}
        job_name: '*Deploy*'
        url: ${{ secrets.SLACK_WEBHOOK }}

自前で書いてもいいし、Marketplaceにもいっぱいある

homoluctus/slatify はいくつか試した中でいい感じだった。

Node.js

    - uses: actions/setup-node@v1
      with:
        node-version: '12.x'

Using Node.js with GitHub Actions - GitHub ヘルプ

AWS API Key

    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-east-2

"Configure AWS Credentials" Action For GitHub Actions · Actions · GitHub Marketplace

ECR

    - name: Login to Amazon ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v1

    - name: Build, tag, and push image to Amazon ECR
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        ECR_REPOSITORY: my-ecr-repo
        IMAGE_TAG: ${{ github.sha }}
      run: |
        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

    - name: Logout of Amazon ECR
      if: always()
      run: docker logout ${{ steps.login-ecr.outputs.registry }}

aws-actions/amazon-ecr-login: Logs into Amazon ECR with the local Docker client.

yarn キャッシュ

    - name: Get yarn cache
      id: yarn-cache
      run: echo "::set-output name=dir::$(yarn cache dir)"
    
    - uses: actions/cache@v1
      with:
        path: ${{ steps.yarn-cache.outputs.dir }}
        key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
        restore-keys: |
          ${{ runner.os }}-yarn-

cache/examples.md at master · actions/cache

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?