覚書

Github Actionsを活用する

Goのテストを実行:

---
name: CI
on: [push]
jobs:
- run\_test:
    - name: Go Test
    - runs-on: ubuntu-latest
    - steps:

        - - name: Set up Go 1.13
            - uses: actions/setup-go@v1
            - with:
                - go-version: 1.13
            - id: go

        - - name: Check out code into the Go module directory
            - uses: actions/checkout@v1

        - - name: Run Test
            - run: |
                - make test

リリース:

---
name: Release
on:
  create:
    tags:
      - v*.*.*
    branches:
      - master
  • jobs:
    • release:
      • name: Release on GitHub
      • runs-on: ubuntu-latest
      • steps:
          • name: Check out code
            • uses: actions/checkout@v1
          • name: Validates GO releaser config
            • uses: docker://goreleaser/goreleaser:latest
            • with:
              • args: check
          • name: Create release on GitHub
            • uses: docker://goreleaser/goreleaser:latest
            • with:
              • args: release
            • env:
              • GITHUB_TOKEN: ${{secrets.GORELEASER_TOKEN}}
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
  hooks:
    # you may remove this if you don't use vgo
    - go mod download
    # you may remove this if you don't need go generate
    - go generate ./...
builds:
  - env:
      - CGO_ENABLED=0
    ldflags:
      -X github.com/takaishi/kelm/config.Version={{.Version}}
archive:
  replacements:
    darwin: Darwin
    linux: Linux
    windows: Windows
    amd64: x86_64
checksum:
  name_template: 'checksums.txt'
snapshot:
  name_template: "{{ .Tag }}-next"
changelog:
  sort: asc
  filters:
    exclude:
      - '^docs:'
      - '^test:'
brew:
  github:
    owner: takaishi
    name: homebrew-fomulas
  commit_author:
    name: goreleaserbot
    email: goreleaser@carlosbecker.com
  description: "CLI tool to Generate and insert markdown's table of contents"
  homepage: "https://github.com/takaishi/kelm"
  install: |
    bin.install Dir['kelm']
  test: |
    system "#{bin}/kelm"

コンテナイメージのビルドを行う場合:

---
name: Docker Image CI
on:
  push:
    tags:
      - v*.*.*
env:
  DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN}}
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Build the Docker image
        run: |
          tag=$(echo ${{ github.ref }} | sed 's/refs\/tags\///g' | tr -d '\n')
          docker login -u rtakaishi -p $DOCKER_HUB_TOKEN
          docker build . --file Dockerfile --tag rtakaishi/openstack-sg-controller:${tag}
          docker push rtakaishi/openstack-sg-controller:${tag}