🐥

Github Actions設定備忘録(自分用)

2022/02/16に公開
name: Build and Release

on:
  push:
    tags:
      - "v*"

env:
  DOCKER_IMAGE: ghcr.io/namespace/image_name

jobs:
  setup-build-publish-deploy:
    name: Setup, Build, Publish
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: version
        id: version
        run: |
          echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"

      # これがないとdocker/build-push-actionでcache-toを使えない
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: login to Github Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN}}

      - name: Container Build and Push
        uses: docker/build-push-action@v2
        with:
          tags: ${{ env.DOCKER_IMAGE }}:${{ env.VERSION }}
          cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache
          cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache
          build-args: |
            VERSION=${{ env.VERSION }}
            ARG_GO_MODULES_TOKEN=${{env.GO_MODULES_TOKEN}}
          outputs: type=registry
          push: true

      - name: Deployment yaml
        uses: n-creativesystem/variable-template@v1
        with:
          input: input/filename.yaml
          output: output/filename.yaml
        env:
	  env_name: value

      - name: Notify to Slack channel
        if: ${{ success() }}
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
          SLACK_USERNAME: GitHUb Actions
          SLACK_TITLE: Workflow succeeded
          SLACK_ICON: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
          SLACK_MESSAGE: "Succeeded Run number : #${{ github.run_number }}"

      - name: Notify to Slack channel
        if: ${{ failure() }}
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
          SLACK_USERNAME: GitHUb Actions
          SLACK_TITLE: Workflow failed
          SLACK_ICON: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
          SLACK_COLOR: danger
          SLACK_MESSAGE: "Failed Run number : #${{ github.run_number }}"

Discussion

ログインするとコメントできます