mirror of
https://github.com/Luzifer/wiki.git
synced 2024-11-08 06:40:09 +00:00
CI: Replace old build-system
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
d89b275c5f
commit
8f85b37687
4 changed files with 145 additions and 16 deletions
79
.github/workflows/test-and-build.yml
vendored
Normal file
79
.github/workflows/test-and-build.yml
vendored
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
name: test-and-build
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ['*']
|
||||||
|
tags: ['v*']
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
issues: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test-and-build:
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: luzifer/archlinux
|
||||||
|
env:
|
||||||
|
CGO_ENABLED: 0
|
||||||
|
GOPATH: /go
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Enable custom AUR package repo
|
||||||
|
run: echo -e "[luzifer]\nSigLevel = Never\nServer = https://archrepo.hub.luzifer.io/\$arch" >>/etc/pacman.conf
|
||||||
|
|
||||||
|
- name: Install required packages
|
||||||
|
run: |
|
||||||
|
pacman -Syy --noconfirm \
|
||||||
|
awk \
|
||||||
|
curl \
|
||||||
|
diffutils \
|
||||||
|
git \
|
||||||
|
go \
|
||||||
|
golangci-lint-bin \
|
||||||
|
make \
|
||||||
|
nodejs-lts-hydrogen \
|
||||||
|
npm \
|
||||||
|
tar \
|
||||||
|
trivy \
|
||||||
|
unzip \
|
||||||
|
which \
|
||||||
|
zip
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Marking workdir safe
|
||||||
|
run: git config --global --add safe.directory /__w/wiki/wiki
|
||||||
|
|
||||||
|
- name: 'Lint and test code'
|
||||||
|
run: |
|
||||||
|
go test -cover -v ./...
|
||||||
|
golangci-lint run ./...
|
||||||
|
|
||||||
|
- name: Build release
|
||||||
|
run: make publish
|
||||||
|
env:
|
||||||
|
FORCE_SKIP_UPLOAD: 'true'
|
||||||
|
MOD_MODE: readonly
|
||||||
|
NO_TESTS: 'true'
|
||||||
|
PACKAGES: '.'
|
||||||
|
|
||||||
|
- name: Extract changelog
|
||||||
|
run: 'awk "/^#/ && ++c==2{exit}; /^#/f" "History.md" | tail -n +2 >release_changelog.md'
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
uses: ncipollo/release-action@v1
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
artifacts: '.build/*'
|
||||||
|
bodyFile: release_changelog.md
|
||||||
|
draft: false
|
||||||
|
generateReleaseNotes: false
|
||||||
|
|
||||||
|
...
|
|
@ -1,12 +0,0 @@
|
||||||
---
|
|
||||||
|
|
||||||
image: "reporunner/golang-alpine"
|
|
||||||
checkout_dir: /go/src/github.com/Luzifer/wiki
|
|
||||||
|
|
||||||
commands:
|
|
||||||
- make publish
|
|
||||||
|
|
||||||
environment:
|
|
||||||
CGO_ENABLED: 0
|
|
||||||
GO111MODULE: on
|
|
||||||
MOD_MODE: readonly
|
|
7
Makefile
7
Makefile
|
@ -1,9 +1,8 @@
|
||||||
default: generate
|
default: generate
|
||||||
|
|
||||||
generate:
|
generate:
|
||||||
docker run --rm -ti -v $(CURDIR):$(CURDIR) -w $(CURDIR)/src node:12-alpine \
|
docker run --rm -ti -v $(CURDIR):$(CURDIR) -w $(CURDIR)/src node:alpine \
|
||||||
sh -exc "npx npm@lts ci && npx npm@lts run build && chown -R $(shell id -u) ../frontend node_modules"
|
sh -exc "npm ci && node ci/build.mjs && chown -R $(shell id -u) ../frontend node_modules"
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
curl -sSLo golang.sh https://raw.githubusercontent.com/Luzifer/github-publish/master/golang.sh
|
bash ./ci/build.sh
|
||||||
bash golang.sh
|
|
||||||
|
|
63
ci/build.sh
Normal file
63
ci/build.sh
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
osarch=(
|
||||||
|
darwin/amd64
|
||||||
|
darwin/arm64
|
||||||
|
linux/amd64
|
||||||
|
linux/arm
|
||||||
|
linux/arm64
|
||||||
|
windows/amd64
|
||||||
|
)
|
||||||
|
|
||||||
|
function go_package() {
|
||||||
|
cd "${4}"
|
||||||
|
|
||||||
|
local outname="${3}"
|
||||||
|
[[ $1 == windows ]] && outname="${3}.exe"
|
||||||
|
|
||||||
|
log "=> Building ${3} for ${1}/${2}..."
|
||||||
|
CGO_ENABLED=0 GOARCH=$2 GOOS=$1 go build \
|
||||||
|
-ldflags "-s -w -X main.version=${version}" \
|
||||||
|
-mod=readonly \
|
||||||
|
-trimpath \
|
||||||
|
-o "${outname}"
|
||||||
|
|
||||||
|
if [[ $1 == linux ]]; then
|
||||||
|
log "=> Packging ${3} as ${3}_${1}_${2}.tgz..."
|
||||||
|
tar -czf "${builddir}/${3}_${1}_${2}.tgz" "${outname}"
|
||||||
|
else
|
||||||
|
log "=> Packging ${3} as ${3}_${1}_${2}.zip..."
|
||||||
|
zip "${builddir}/${3}_${1}_${2}.zip" "${outname}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm "${outname}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function go_package_all() {
|
||||||
|
for oa in "${osarch[@]}"; do
|
||||||
|
local os=$(cut -d / -f 1 <<<"${oa}")
|
||||||
|
local arch=$(cut -d / -f 2 <<<"${oa}")
|
||||||
|
(go_package "${os}" "${arch}" "${1}" "${2}")
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function log() {
|
||||||
|
echo "[$(date +%H:%M:%S)] $@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
root=$(pwd)
|
||||||
|
builddir="${root}/.build"
|
||||||
|
version="$(git describe --tags --always || echo dev)"
|
||||||
|
|
||||||
|
log "Building version ${version}..."
|
||||||
|
|
||||||
|
log "Resetting output directory..."
|
||||||
|
rm -rf "${builddir}"
|
||||||
|
mkdir -p "${builddir}"
|
||||||
|
|
||||||
|
log "Building Server..."
|
||||||
|
go_package_all "wiki" "."
|
||||||
|
|
||||||
|
log "Generating SHA256SUMS file..."
|
||||||
|
(cd "${builddir}" && sha256sum * | tee SHA256SUMS)
|
Loading…
Reference in a new issue