Skip to content

Commit

Permalink
Merge pull request #236 from JM-Lemmi/build/versioning
Browse files Browse the repository at this point in the history
Dynamically get Version for compilation
  • Loading branch information
JM-Lemmi committed Feb 15, 2024
2 parents 2d096b1 + b84d4c1 commit c8c7977
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 67 deletions.
12 changes: 12 additions & 0 deletions .github/scripts/generate-version.sh
@@ -0,0 +1,12 @@
#! /bin/bash
DIR="$(cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
cd "$DIR" || exit 1

if [[ $(git tag -l --contains HEAD) ]]; then
echo -n $(git tag -l --contains HEAD) > ../../cmd/ical-relay/VERSION
else
echo -n $(git rev-parse --short HEAD) > ../../cmd/ical-relay/VERSION
fi
if ! git diff --quiet; then
echo -n "-dirty" >> ../../cmd/ical-relay/VERSION
fi
40 changes: 40 additions & 0 deletions .github/workflows/compile.yml
@@ -0,0 +1,40 @@
name: Compile

# Run workflow on tags starting with v (eg. v2, v1.2.0)
on:
push:

jobs:
Compile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-go@v4
with:
go-version: '1.18.0' # The Go version to download (if necessary) and use.
- run: go generate cmd/ical-relay/main.go
- run: go build -o ./bin/ical-relay ./cmd/ical-relay/
- uses: actions/upload-artifact@v3
with:
name: ical-relay
path: ./bin/ical-relay

Package-Docker:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
file: ./cmd/ical-relay/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm
push: false # Will only build if this is not here
49 changes: 0 additions & 49 deletions .github/workflows/docker.yml

This file was deleted.

45 changes: 43 additions & 2 deletions .github/workflows/executable.yml → .github/workflows/package.yml
@@ -1,4 +1,4 @@
name: Compile Binary
name: Package

# Run workflow on tags starting with v (eg. v2, v1.2.0)
on:
Expand All @@ -7,6 +7,45 @@ on:
- v*

jobs:
Package-Docker:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/${{ github.repository }}
# generate Docker tags based on the following events/attributes
tags: |
type=semver,pattern={{raw}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=ref,event=branch
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- 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: ${{ github.token }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
file: ./cmd/ical-relay/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm
push: true # Will only build if this is not here
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


Compile:
runs-on: ubuntu-latest
steps:
Expand All @@ -16,13 +55,14 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: '1.18.0' # The Go version to download (if necessary) and use.
- run: go generate cmd/ical-relay/main.go
- run: go build -o ./bin/ical-relay ./cmd/ical-relay/ && strip ./bin/ical-relay
- uses: actions/upload-artifact@v3
with:
name: ical-relay
path: ./bin/ical-relay

Package:
Package-deb:
needs: Compile
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -64,3 +104,4 @@ jobs:
with:
name: ical-relay.deb
path: ${{steps.package.outputs.file_name}}

1 change: 1 addition & 0 deletions .github/workflows/test.yml
Expand Up @@ -18,6 +18,7 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: 1.19
- run: go generate cmd/ical-relay/main.go

- name: Run tests
run: go test ./cmd/ical-relay/...
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -14,4 +14,5 @@ notifystore/
postgres-data
__debug_bin*
cmd/ical-relay/db/*
.vscode/*
.vscode/*
VERSION
13 changes: 0 additions & 13 deletions README.md
Expand Up @@ -45,19 +45,6 @@ Run a notifier manually:
/usr/bin/ical-relay --notifier <name> --config config.yml
```

## Docker Container

```
docker run -d -p 8080:80 -v ~/ical-relay/:/etc/ical-relay/ ghcr.io/jm-lemmi/ical-relay
```

## Build from Source

Clone this repo then either:

* Run from source: `go run .`
* Build and run: `go build . && ./ical-relay`

# Config

```yaml
Expand Down
3 changes: 2 additions & 1 deletion cmd/ical-relay/Dockerfile
@@ -1,10 +1,11 @@
FROM golang:alpine AS build

RUN apk --update add git
RUN apk --update add git bash

WORKDIR /app
COPY . /app

RUN go generate ./cmd/ical-relay/
RUN go build -o ./cmd/ical-relay/ical-relay ./cmd/ical-relay/

FROM alpine AS run
Expand Down
6 changes: 5 additions & 1 deletion cmd/ical-relay/main.go
@@ -1,6 +1,8 @@
package main

import (
_ "embed"

"html/template"
"net/http"
"os"
Expand All @@ -10,7 +12,9 @@ import (
log "github.com/sirupsen/logrus"
)

var version = "2.0.0-beta.7.4"
//go:generate ../../.github/scripts/generate-version.sh
//go:embed VERSION
var version string // If you are here due to a compile error, run go generate

var configPath string
var conf Config
Expand Down
4 changes: 4 additions & 0 deletions development.md
Expand Up @@ -18,6 +18,10 @@ adding a new pkg you also need to add it to `go work` to use it.
go work use ./pkg/<newname>
```

## compiling

please first generate the version number: `./.github/scripts/generate-version.sh` then build with `go build -o ./bin/ical-relay ./cmd/ical-relay/`

## Development Docker Compose

```
Expand Down

0 comments on commit c8c7977

Please sign in to comment.