Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
feat(ci): add ci workflows (#5)
Browse files Browse the repository at this point in the history
* feat(ci): add branch workflow

* add cr and ct yaml files

* remove linting until I can figure out whats wrong

* move ci to devtools container

* remote tty from in-docker

* try install

* not install

* install proper golangci-lint path

* add release workflow and fix failing lint

* skip setting in dependencies for now
  • Loading branch information
mjpitz committed Oct 20, 2021
1 parent a1f2201 commit 4dd9b40
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 19 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Branch

on: pull_request

jobs:
container:
name: Build and Test Container
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Devtools
run: |
make docker/devtools
- name: Lint
run: |
make in-docker TARGETS="lint"
- name: Test
run: make in-docker TARGETS="test"

- name: Distribute
run: make in-docker TARGETS="dist"

chart:
name: Lint and Test Chart
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: v3.4.1

# Python is required because `ct lint` runs Yamale (https://github.com/23andMe/Yamale) and
# yamllint (https://github.com/adrienverge/yamllint) which require Python
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.0.1
with:
version: v3.3.0

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --config ct.yaml)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
- name: Run chart-testing (lint)
run: ct lint --config ct.yaml --check-version-increment=false

# TODO: turn back on

# - name: Create kind cluster
# uses: helm/kind-action@v1.1.0
# if: steps.list-changed.outputs.changed == 'true'

# - name: Run chart-testing (install)
# run: ct install --config ct.yaml
135 changes: 135 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Release

on:
push:
tags:
- v*

jobs:
distribute:
name: Distribute Binaries and Containers
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Devtools
run: |
make docker/devtools
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Registry
run: echo "${REGISTRY_PASSWORD}" | docker login -u "${REGISTRY_USERNAME}" --password-stdin ghcr.io
env:
REGISTRY_USERNAME: ${{ secrets.GHCR_REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.GHCR_REGISTRY_PUSH_PASSWORD }}

- name: Distribute Binaries
run: |
VERSION=${GITHUB_REF##*/v} make in-docker TARGETS="dist"
- name: Distribute Container Image
run: |
VERSION=${GITHUB_REF##*/v} make release/docker
chart:
name: Publish Chart
runs-on: ubuntu-latest

needs:
- container

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Prepare
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
mkdir .cr-index/
mkdir .cr-release-packages/
sudo apt-get install wget
- name: Install yq
env:
VERSION: 4.9.7
run: |
wget https://github.com/mikefarah/yq/releases/download/v${VERSION}/yq_linux_amd64 -O ./yq
chmod +x ./yq
sudo mv ./yq /usr/bin/yq
- name: Install chart-releaser
env:
VERSION: 1.2.1
run: |
wget https://github.com/helm/chart-releaser/releases/download/v${VERSION}/chart-releaser_${VERSION}_linux_amd64.tar.gz -O cr.tgz
tar zxf cr.tgz cr && rm cr.tgz
sudo mv ./cr /usr/bin/cr
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.4.1

- name: Set Versions
shell: bash
run: |
export VERSION="\"${GITHUB_REF##*/v}\""
yq e ".version = ${VERSION}" -i ./charts/aetherfs-hub/Chart.yaml
yq e ".appVersion = ${VERSION}" -i ./charts/aetherfs-hub/Chart.yaml
yq e ".version = ${VERSION}" -i ./charts/aetherfs/Chart.yaml
yq e ".appVersion = ${VERSION}" -i ./charts/aetherfs/Chart.yaml
# TODO: Setup GPG signing
# - name: Prepare GPG key
# run: |
# gpg_dir=.cr-gpg
# mkdir "$gpg_dir"

# keyring="$gpg_dir/secring.gpg"
# base64 -d <<< "$GPG_KEYRING_BASE64" > "$keyring"

# passphrase_file="$gpg_dir/passphrase"
# echo "$GPG_PASSPHRASE" > "$passphrase_file"

# echo "CR_PASSPHRASE_FILE=$passphrase_file" >> "$GITHUB_ENV"
# echo "CR_KEYRING=$keyring" >> "$GITHUB_ENV"
# env:
# GPG_KEYRING_BASE64: "${{ secrets.GPG_KEYRING_BASE64 }}"
# GPG_PASSPHRASE: "${{ secrets.GPG_PASSPHRASE }}"

# - name: Add dependency chart repos
# run: |
# helm repo add bitnami https://charts.bitnami.com/bitnami

# package and upload manually
# chart-releaser has some minor headaches when tags already exist at commit.
- name: Package
run: |
cr package charts/aetherfs-hub
cr package charts/aetherfs
- name: Upload
uses: softprops/action-gh-release@v1
with:
files: |
.cr-release-packages/*
- name: Index
run: |
cr index
cp .cr-index/index.yaml docs/index.yaml
git add docs/index.yaml
git commit -m "release: charts"
git push
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.cr-release-packages/
.cr-index/

/charts/**/Chart.lock
/charts/**/*.tgz
/gen/
Expand Down
8 changes: 8 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# env needed for release:
# - VERSION
# - GITHUB_TOKEN

project_name: aetherfs

snapshot:
Expand Down Expand Up @@ -28,3 +32,7 @@ checksum:
name_template: 'aetherfs_checksums.txt'
extra_files:
- glob: "**/aetherfs_proto.tar.gz"

release:
header: ""
footer: ""
38 changes: 20 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ Targets:

docker rebuild the aetherfs docker container
docker/devtools rebuild docker container containing developer tools
docker/release releases aetherfs (will likely move)
docker/shell spins up an interactive shell with all dev tools
in-docker run targets in docker (useful to avoid local deps)

lint lints the code base
legal prepends legal header to source code
test run tests
gen regenerate the API code from protocol buffers
dist recompiles aetherfs binaries
release releases aetherfs (will likely move)

endef
export HELP_TEXT
Expand All @@ -36,7 +38,9 @@ docker/devtools: .docker/devtools
docker build ./docker/devtools -t $(SKAFFOLD_DEFAULT_REPO)/aetherfs-devtools

in-docker:
docker run --rm -it \
docker run --rm -i \
-e VERSION \
-e GITHUB_TOKEN \
-v $(CWD):/home \
-w /home \
$(SKAFFOLD_DEFAULT_REPO)/aetherfs-devtools \
Expand All @@ -50,12 +54,26 @@ docker/shell: .docker/shell
$(SKAFFOLD_DEFAULT_REPO)/aetherfs-devtools \
sh

docker/release:
docker buildx build . \
--platform linux/amd64,linux/arm64 \
--tag $(SKAFFOLD_DEFAULT_REPO)/aetherfs:latest \
--tag $(SKAFFOLD_DEFAULT_REPO)/aetherfs:$(VERSION) \
--file ./docker/aetherfs/Dockerfile \
--push

# actual targets

lint:
./scripts/lint.sh

legal: .legal
.legal:
addlicense -f ./legal/header.txt -skip yaml -skip yml docker internal proto scripts web/public web/src

test:
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...

gen: .gen
.gen:
./scripts/buf.sh
Expand All @@ -65,19 +83,3 @@ dist: .dist
./scripts/dist-web.sh
make legal
./scripts/dist-go.sh

# release - used to generate core release assets such as binaries and container images.

release:
docker run --rm -it \
-v $(CWD):/home \
-w /home \
$(SKAFFOLD_DEFAULT_REPO)/aetherfs-devtools \
sh -c "goreleaser"

docker buildx build . \
--platform linux/amd64,linux/arm64 \
--tag $(SKAFFOLD_DEFAULT_REPO)/aetherfs:latest \
--tag $(SKAFFOLD_DEFAULT_REPO)/aetherfs:$(VERSION) \
--file ./docker/aetherfs/Dockerfile \
--push
5 changes: 5 additions & 0 deletions cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
charts-repo: https://aetherfs.tech/charts/
owner: mjpitz
git-repo: aetherfs
release-name-template: "v{{ .Version }}"
pages-branch: "main"
7 changes: 7 additions & 0 deletions ct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://github.com/helm/chart-testing#configuration
remote: origin
chart-dirs:
- charts
helm-extra-args: --timeout 600s
target-branch: main
validate-maintainers: false
2 changes: 1 addition & 1 deletion docker/devtools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ RUN GOBIN=/usr/local/bin go get \
moul.io/protoc-gen-gotemplate@v1.11.2 \
github.com/google/addlicense@v1.0.0 \
github.com/goreleaser/goreleaser@v0.177.0 \
github.com/golangci/golangci-lint@v1.42.1 \
github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.1 \
1 change: 1 addition & 0 deletions internal/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
)

//nolint:typecheck
//go:embed dist/*
var assets embed.FS

Expand Down

0 comments on commit 4dd9b40

Please sign in to comment.