Files
TrollSSH/.github/workflows/ci.yml
T
2026-07-13 17:58:48 +07:00

85 lines
2.4 KiB
YAML

name: CI
on:
push:
branches: ["**"]
tags: ["v*"]
pull_request:
permissions:
contents: read
packages: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Format check
run: test -z "$(gofmt -l src)"
- name: Vet
run: go vet ./src/
- name: Staticcheck
uses: dominikh/staticcheck-action@v1
with:
install-go: false
- name: Build
run: go build -o trollssh ./src
- name: Unit tests
run: go test -race ./src/
docker:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Determine push conditions
id: should_push
run: |
if [[ "${{ github.event_name }}" == "push" && ( "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == refs/tags/v* ) ]]; then
echo "push=true" >> "$GITHUB_OUTPUT"
else
echo "push=false" >> "$GITHUB_OUTPUT"
fi
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/yuzuzensai/trollssh
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern=v{{version}}
type=sha,prefix=sha-,format=short
- name: Log in to GHCR
if: steps.should_push.outputs.push == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build (and push) image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ steps.should_push.outputs.push == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false