Implement GitHub actions CI

This commit is contained in:
Lukas Schulte Pelkum 2021-04-18 21:31:07 +02:00
parent e6f0d0948b
commit 239ad901dd
No known key found for this signature in database
GPG Key ID: 408DA7CA81DB885C
4 changed files with 74 additions and 4 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: 'lus'

43
.github/workflows/docker.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: docker
on:
push:
branches:
- main
- develop
paths-ignore:
- '**.md'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2
- name: define branch name
run: echo "BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
- name: define commit hash
run: echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: define staging tag
if: env.BRANCH == 'develop'
run: echo "TAG=staging" >> $GITHUB_ENV
- name: define latest tag
if: env.BRANCH == 'main'
run: echo "TAG=latest" >> $GITHUB_ENV
- name: set up qemu
uses: docker/setup-qemu-action@v1
- name: set up buildx
uses: docker/setup-buildx-action@v1
- name: log in to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: lus
password: ${{ secrets.CR_TOKEN }}
- name: build and push
uses: docker/build-push-action@v2
with:
push: true
tags: ghcr.io/lus/pasty:${{ env.TAG }}
build-args:
PASTY_VERSION=${{ env.BRANCH }}-${{ env.COMMIT_HASH }}

21
.github/workflows/general.yml vendored Normal file
View File

@ -0,0 +1,21 @@
name: general
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v2
- name: setup go environment
uses: actions/setup-go@v2
with:
go-version: ^1.16
- name: download dependencies
run: |
go version
go mod download
- name: build
run: |
go build ./cmd/pasty/

View File

@ -1,15 +1,20 @@
# Build the application
# Choose the golang image as the build base image
FROM golang:1.16-alpine AS build
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh build-base
# Define the directory we should work in
WORKDIR /app
# Download the necessary go modules
COPY go.mod go.sum ./
RUN go mod download
# Build the application
ARG PASTY_VERSION=unset-debug
COPY . .
RUN go build \
-o pasty \
-ldflags "\
-X github.com/lus/pasty/internal/static.Version=$(git rev-parse --abbrev-ref HEAD)-$(git describe --tags --abbrev=0)-$(git log --pretty=format:'%h' -n 1)" \
-X github.com/lus/pasty/internal/static.Version=$PASTY_VERSION" \
./cmd/pasty/main.go
# Run the application in an empty alpine environment