Skip to content

Commit

Permalink
ci: workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed Sep 12, 2024
1 parent 342d302 commit b23fd25
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 20 deletions.
Binary file added .github/assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---

on: # yamllint disable-line rule:truthy
pull_request:
branches:
- master

name: 🧹 Fix coding standards

jobs:
commit-linting:
timeout-minutes: 4
runs-on: ubuntu-latest
concurrency:
cancel-in-progress: true
group: commit-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
permissions:
contents: read
pull-requests: read
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🧐 Lint commits using "commitlint"
uses: wagoid/[email protected]
with:
configFile: ${{ github.workspace }}/.github/.commitlint.config.mjs
failOnWarnings: false
failOnErrors: true
helpURL: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'

yaml-linting:
timeout-minutes: 4
runs-on: ubuntu-latest
concurrency:
cancel-in-progress: true
group: yaml-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
permissions:
contents: read
pull-requests: read
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🧐 Lint YAML files
uses: ibiqlik/[email protected]
with:
config_file: .github/.yamllint.yaml
file_or_dir: '.'
strict: true

markdown-linting:
timeout-minutes: 4
runs-on: ubuntu-latest
concurrency:
cancel-in-progress: true
group: markdown-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🧐 Lint Markdown files
uses: DavidAnson/[email protected]
with:
config: '.github/.markdownlint.json'
globs: |
**/*.md
!CHANGELOG.md
ansible-linting:
timeout-minutes: 4
runs-on: ubuntu-latest
concurrency:
cancel-in-progress: true
group: ansible-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
env:
YAMLLINT_CONFIG_FILE: '${{ github.workspace }}/.github/.yamllint.yaml'
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🧐 Lint Ansible files
uses: ansible/[email protected]
with:
args: '-c ${{ github.workspace }}/.github/.ansible-lint.yml'
43 changes: 43 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---

on: # yamllint disable-line rule:truthy
workflow_run:
types:
- completed
workflows:
- '🧪 Test Docker images'

name: 📥 Merge pull requests

jobs:
merge:
runs-on: ubuntu-latest
timeout-minutes: 5
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
(
(github.actor == 'renovate[bot]' &&
startsWith(github.event.workflow_run.head_commit.message, 'deps(deps)')
) ||
(github.actor == 'lotyp' &&
startsWith(github.event.workflow_run.head_commit.message, 'chore(master)')
)
)
steps:
- name: 🙋‍♂️ Request reviewer from @way-finder-bot
uses: wayofdev/gh-actions/actions/github/pull-request/[email protected]
with:
reviewer: 'way-finder-bot'
github-token: "${{ secrets.WAY_FINDER_BOT_TOKEN }}"

- name: 🙋‍♂️ Assign @way-finder-bot
uses: wayofdev/gh-actions/actions/github/pull-request/[email protected]
with:
assignee: 'way-finder-bot'
github-token: "${{ secrets.WAY_FINDER_BOT_TOKEN }}"

- name: ✅ Approve pull request
uses: wayofdev/gh-actions/actions/github/pull-request/[email protected]
with:
github-token: "${{ secrets.WAY_FINDER_BOT_TOKEN }}"
92 changes: 73 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
export DOCKER_BUILDKIT ?= 1
export COMPOSE_DOCKER_CLI_BUILD ?= 1

# Docker binary to use, when executing docker tasks
DOCKER ?= docker

IMAGE_NAMESPACE ?= wayofdev/nginx
IMAGE_TEMPLATE ?= k8s-alpine
IMAGE_TAG ?= $(IMAGE_NAMESPACE):$(IMAGE_TEMPLATE)-latest
Expand All @@ -13,6 +16,34 @@ CACHE_FROM ?= $(IMAGE_TAG)
OS ?= $(shell uname)
CURRENT_DIR ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

YAML_CONFIG_PATH ?= .github/.yamllint.yaml

YAML_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(PWD):/data \
cytopia/yamllint:latest \
-c $(YAML_CONFIG_PATH) \
-f colored .

ACTION_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(shell pwd):/repo \
--workdir /repo \
rhysd/actionlint:latest \
-color

MARKDOWN_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(shell pwd):/app \
--workdir /app \
davidanson/markdownlint-cli2-rules:latest \
--config ".github/.markdownlint.json"

ANSIBLE_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(shell pwd):/code \
-e YAMLLINT_CONFIG_FILE=$(YAML_CONFIG_PATH) \
--workdir /code \
pipelinecomponents/ansible-lint:latest \
ansible-lint --show-relpath --config-file ".github/.ansible-lint.yml"

#
# Self documenting Makefile code
# ------------------------------------------------------------------------------------
ifneq ($(TERM),)
Expand All @@ -36,7 +67,7 @@ else
WHITE := ""
RST := ""
endif
MAKE_LOGFILE = /tmp/docker-nginx.log
MAKE_LOGFILE = /tmp/wayofdev-docker-nginx.log
MAKE_CMD_COLOR := $(BLUE)

default: all
Expand All @@ -45,29 +76,31 @@ help: ## Show this menu
@echo 'Management commands for package:'
@echo 'Usage:'
@echo ' ${MAKE_CMD_COLOR}make${RST} Builds default image and then runs dgoss tests'
@grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " ${MAKE_CMD_COLOR}make %-21s${RST} %s\n", $$1, $$2}'
@grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf " ${MAKE_CMD_COLOR}make %-21s${RST} %s\n", $$1, $$2}'
@echo
@echo ' 📑 Logs are stored in $(MAKE_LOGFILE)'
@echo
@echo ' 📦 Package docker-nginx (github.com/wayofdev/docker-nginx)'
@echo ' 🤠 Author Andrij Orlenko (github.com/lotyp)'
@echo ' 🤠 Author the dev (github.com/lotyp)'
@echo ' 🏢 ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}'
@echo
.PHONY: help

.EXPORT_ALL_VARIABLES:

#
# Default action
# Defines default command when `make` is executed without additional parameters
# ------------------------------------------------------------------------------------
all: hooks generate build test
all: generate build test
PHONY: all


#
# Docker Actions
# ------------------------------------------------------------------------------------
build: ## Build default docker image
cd $(CURRENT_DIR)$(DOCKERFILE_DIR); \
docker build -t $(IMAGE_TAG) .
$(DOCKER) build -t $(IMAGE_TAG) .
PHONY: build

analyze: ## Analyze docker image
Expand All @@ -80,11 +113,6 @@ build-from-cache: ## Build default docker image using cached layers
docker build --cache-from $(CACHE_FROM) . -t $(IMAGE_TAG)
PHONY: build-from-cache

test: ## Run dgoss tests over docker images
set -eux
GOSS_FILES_STRATEGY=cp GOSS_FILES_PATH=$(DOCKERFILE_DIR) dgoss run --add-host app:127.0.0.1 -t $(IMAGE_TAG)
.PHONY: test

pull: ## Pulls docker image from upstream
docker pull $(IMAGE_TAG)
.PHONY: pull
Expand All @@ -97,7 +125,7 @@ ssh: ## Login into built image
docker run --rm -it -v $(PWD)/:/opt/docker-nginx $(IMAGE_TAG) sh
.PHONY: ssh


#
# Ansible Actions
# ------------------------------------------------------------------------------------
generate: ## Generates dockerfiles from ansible templates
Expand All @@ -108,23 +136,49 @@ clean: ## Cleans up generated files
rm -rf ./dist/*
PHONY: clean

#
# Testing
# ------------------------------------------------------------------------------------
test: ## Run dgoss tests over docker images
set -eux
GOSS_SLEEP="0.4" GOSS_WAIT_OPTS="-r 40s -s 2s > /dev/stdout" GOSS_FILES_STRATEGY=cp GOSS_FILES_PATH=$(DOCKERFILE_DIR) dgoss run --add-host app:127.0.0.1 -t $(IMAGE_TAG)
.PHONY: test

# Code Quality, Git, Linting, Testing
#
# Code Quality, Git, Linting
# ------------------------------------------------------------------------------------
hooks: ## Install git hooks from pre-commit-config
pre-commit install
pre-commit install --hook-type commit-msg
pre-commit autoupdate
.PHONY: hooks

lint: lint-yaml lint-actions lint-md lint-ansible ## Runs all linting commands
.PHONY: lint

lint-yaml: ## Lints yaml files inside project
yamllint .
@$(YAML_LINT_RUNNER) | tee -a $(MAKE_LOGFILE)
.PHONY: lint-yaml

lint-actions: ## Lint all github actions
@$(ACTION_LINT_RUNNER) | tee -a $(MAKE_LOGFILE)
.PHONY: lint-actions

lint-md: ## Lint all markdown files using markdownlint-cli2
@$(MARKDOWN_LINT_RUNNER) --fix "**/*.md" "!CHANGELOG.md" "!app/vendor" "!app/node_modules" | tee -a $(MAKE_LOGFILE)
.PHONY: lint-md

lint-md-dry: ## Lint all markdown files using markdownlint-cli2 in dry-run mode
@$(MARKDOWN_LINT_RUNNER) "**/*.md" "!CHANGELOG.md" "!app/vendor" "!app/node_modules" | tee -a $(MAKE_LOGFILE)
.PHONY: lint-md-dry

lint-ansible: ## Lint ansible files inside project
ansible-lint .
@$(ANSIBLE_LINT_RUNNER) . | tee -a $(MAKE_LOGFILE)
.PHONY: lint-ansible

lint-docker: ## Run hadolint linter over dist Dockerfiles
hadolint -V ./dist/dev-alpine/Dockerfile
hadolint -V ./dist/k8s-alpine/Dockerfile
.PHONY: lint-docker
#
# Release
# ------------------------------------------------------------------------------------
commit: ## Run commitizen to create commit message
czg commit --config="./.github/.cz.config.js"
.PHONY: commit
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

This image is used together with [wayofdev/docker-php-dev](https://github.com/wayofdev/docker-php-dev) and other WOD images, to create local development environment for our projects.

![Screenshot](assets/screenshot.png)
![Screenshot](.github/assets/screenshot.png)

## ⚙️ Development

Expand Down

0 comments on commit b23fd25

Please sign in to comment.