Skip to content

update pipelines and info #98

update pipelines and info

update pipelines and info #98

Workflow file for this run

name: CI
on:
pull_request:
jobs:
Build-and-Push-Image:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"
name: Build and Push Image to Image registry
env:
REGISTRY: docker.io
defaults:
run:
shell: bash
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: '1.20'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Build Code
run: |
go mod download
go build -v .
- name: Initialize Pipeline
uses: mshick/add-pr-comment@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: "@${{ github.actor }} GitHub Actions has started building this code. Check status at 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'"
message-id: ${{ github.run_id }}-${{ github.run_attempt }}
- name: Generate Vars
id: generate_vars
run: |
# Just Tag
IMAGE_TAG=pr-${{ github.event.pull_request.number }}-$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8)
# Just Image name
IMAGE_NAME=${{ github.repository }}
#Image ID= Name + Tag
IMAGE_ID=$IMAGE_NAME:$IMAGE_TAG
IMAGE_REPO=$REGISTRY/$IMAGE_ID
echo "Image: $IMAGE_REPO"
echo "::set-output name=image::$IMAGE_REPO"
echo "::set-output name=image_name::$IMAGE_NAME"
echo REPO=$IMAGE_NAME >> $GITHUB_ENV
echo IMAGE=$(echo "$REGISTRY/$IMAGE_ID") >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Echo Output
run: |
echo "Image from Output: ${{ steps.generate_vars.outputs.image }}"
echo "Repo from Output: ${{ steps.generate_vars.outputs.image_name }}"
echo "Image from Env: ${{ env.IMAGE }}"
echo "Repo from Env: ${{ env.REPO }}"
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
pull: true
push: true
tags: ${{ env.IMAGE }}
- name: Comment on PR
uses: mshick/add-pr-comment@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: '@${{ github.actor }} Image is available for testing. `docker pull ${{ env.IMAGE }}`'
allow-repeats: false
- name: Notify Failure
if: failure()
uses: mshick/add-pr-comment@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: '@${{ github.actor }} The pipeline failed! You better fix it before anyone else finds out! [Build](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}/checks) has Failed!'
allow-repeats: false
- name: Notify Slack
uses: 8398a7/action-slack@v3
if: always()
with:
status: ${{ job.status }}
fields: repo,author,action,eventName,ref,workflow
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}