Skip to content

Commit

Permalink
chore: prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
axelrindle committed Sep 29, 2024
1 parent e76708c commit d59f370
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 7 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release

on:
push:
tags:
- "v*.*.*"

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
env:
BUILD_VERSION: ${{ github.ref_name }}
OUT_ARCHIVE: "${{ github.event.repository.name }}-${{ github.ref_name }}"
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5

- uses: arduino/setup-task@v2
with:
version: 3.x

- name: Build
run: task build:release

- id: extract-changelog
uses: sean0x42/markdown-extract@v2
with:
file: CHANGELOG.md
pattern: ${{ github.ref_name }}
no-print-matched-heading: true

- name: Create Release
uses: softprops/action-gh-release@v2
if: ${{ !env.ACT }}
with:
body: |
## Changelog
${{ steps.extract-changelog.outputs.markdown }}
files: |
*.tar.gz
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ dist/
*.tar.gz

coverage.out

.task
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

Initial release 🎉
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@

> 📨 Send emails right from your terminal.
We use this tool to send an informational email whenever someone logs in to one of our servers.
Intended usage is via [pam_exec(8)](https://linux.die.net/man/8/pam_exec).

Emails are sent directly via SMTP. The config is read from a json file, see [Config](#config).

The message body is produced via go templates, see [Templates](#templates).

## Installation

Download an archive (`.tar.gz`) from the latest release and run the `install.sh` script.

## Usage

```shell
$ smtp-cli --help
Add the following snippet to `/etc/pam.d/sshd`:

```
session required pam_exec.so /usr/local/bin/smtp-cli -config /usr/local/etc/smtp-cli/config.json -template /usr/local/etc/smtp-cli/template.gotmpl
```

## Config
Expand All @@ -20,10 +33,23 @@ $ smtp-cli --help
"to": [
"info <[email protected]>"
],
"subject": "Neue Anmeldung auf dem Server"
"subject": "New login to the server"
}
```

## Templates

The following variables are made available to the go template:

| Variable | Type |
| --- | --- |
| Host | string |
| User | string |
| RemoteUser | string |
| RemoteHost | string |
| Tty | string |
| Timestamp | time.Time |

## License

[MIT](LICENSE)
12 changes: 9 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version: '3'
vars:
OUT_DIR: dist
OUT_FILE: smtp-cli
OUT_ARCHIVE: smtp-cli

tasks:
build:
Expand All @@ -13,8 +14,9 @@ tasks:
- build
- compile
vars:
BUILD_VERSION: "dev"
BUILD_COMMIT: "sha1"
BUILD_VERSION: "{{ env \"BUILD_VERSION\" | default \"dev\" }}"
BUILD_COMMIT:
sh: git rev-parse --short HEAD
cmd: |
go build \
-ldflags="{{.LDFLAGS}} -X 'main.Version={{.BUILD_VERSION}}' -X 'main.CommitHash={{.BUILD_COMMIT}}' -X 'main.BuildTimestamp={{ now }}'" \
Expand Down Expand Up @@ -47,7 +49,11 @@ tasks:
- cp install.sh "{{.OUT_DIR}}/"
- cp config/smtp-cli.json.example "{{.OUT_DIR}}/smtp-cli.json"
- cp config/template.gotmpl.example "{{.OUT_DIR}}/template.gotmpl"
- tar czvf "{{.OUT_FILE}}.tar.gz" "{{.OUT_DIR}}/"
- tar czvf "{{.OUT_ARCHIVE}}.tar.gz" "{{.OUT_DIR}}/"
sources:
- dist/**
generates:
- "{{.OUT_ARCHIVE}}.tar.gz"

clean:
cmd: rm -rf "{{.OUT_DIR}}"
Expand Down
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var flagTemplate string
func main() {
flag.BoolVar(&flagVersion, "version", false, "Print the tool version and exit.")
flag.StringVar(&flagConfig, "config", "smtp-cli.json", "The config file to use.")
flag.StringVar(&flagTemplate, "template", "template.gotmpl", "The config file to use.")
flag.StringVar(&flagTemplate, "template", "template.gotmpl", "A file to load the go template from.")
flag.Parse()

if flagVersion {
Expand Down

0 comments on commit d59f370

Please sign in to comment.