Skip to content

feat(ci): add automatic tests #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 46 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
version: 2.1

setup: true

orbs:
path-filtering: circleci/[email protected]

executors:
build-environment:
docker:
Expand All @@ -22,7 +27,10 @@ jobs:

- run:
name: Verify Environment
command: sh ./scripts/ci/verify.sh build
command: |
apk update
sh scripts/install/bash.sh $BLOG_BUILD_ENV
bash scripts/ci/verify.sh build

verify-deploy-environment:
executor: deploy-environment
Expand All @@ -32,7 +40,10 @@ jobs:

- run:
name: Verify Environment
command: sh ./scripts/ci/verify.sh deploy
command: |
apk update
sh scripts/install/bash.sh $BLOG_BUILD_ENV
bash scripts/ci/verify.sh deploy

verify-publish-environment:
executor: publish-environment
Expand All @@ -42,7 +53,10 @@ jobs:

- run:
name: Verify Environment
command: sh ./scripts/ci/verify.sh publish
command: |
apk update
sh scripts/install/bash.sh $BLOG_BUILD_ENV
bash scripts/ci/verify.sh publish

build:
executor: build-environment
Expand All @@ -55,7 +69,8 @@ jobs:

command: |
apk update
sh ./scripts/install/make.sh
sh scripts/install/bash.sh $BLOG_BUILD_ENV
bash scripts/install/make.sh
make install-git env=$BLOG_BUILD_ENV
make install-hugo

Expand Down Expand Up @@ -92,7 +107,8 @@ jobs:

command: |
apk update
sh ./scripts/install/make.sh
sh scripts/install/bash.sh $BLOG_BUILD_ENV
bash scripts/install/make.sh
make install-npm
make install-netlify-cli

Expand All @@ -114,28 +130,42 @@ jobs:
name: Install Packages
command: |
apk update
sh ./scripts/install/make.sh
sh scripts/install/bash.sh $BLOG_BUILD_ENV
bash scripts/install/make.sh
make install-docker-cli

- run:
name: Publish To Docker Hub
command: make publish-ci tag=$CIRCLE_TAG username=$DOCKER_USERNAME token=$DOCKER_ACCESS_TOKEN

workflows:
verify:
main:
jobs:
- verify-build-environment
- verify-deploy-environment
- verify-publish-environment

build:
jobs:
- build
- verify-deploy-environment:
filters:
branches:
only:
- main

- verify-publish-environment:
filters:
branches:
only:
- main

deploy:
jobs:
- build


- path-filtering/filter:
name: watchtower

mapping: |
tests/.* run-tests-jobs true

base-revision: main
config-path: .circleci/watchtower.yml

- deploy:
requires:
- build
Expand All @@ -144,8 +174,7 @@ workflows:
branches:
only:
- main
publish:
jobs:

- publish:
filters:
tags:
Expand Down
72 changes: 72 additions & 0 deletions .circleci/watchtower.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
version: 2.1

parameters:
run-tests-jobs:
type: boolean
default: false

executors:
tests-node-environment:
docker:
- image: node:18.7.0-alpine3.16

tests-bats-environment:
docker:
- image: bats/bats:1.7.0

jobs:
tests-bats:
executor: tests-bats-environment

steps:
- checkout

- run:
name: Install Packages

command: |
apk update
sh scripts/install/bash.sh $BLOG_BUILD_ENV
bash scripts/install/make.sh
make install-git env=$BLOG_BUILD_ENV

- run:
name: Add Git Submodules
command: make git-submodules env=$BLOG_BUILD_ENV

- run:
name: Run Tests
command: bats ./tests/_.bats ./tests/install.bats ./tests/shared.bats

tests-node:
executor: tests-node-environment

steps:
- checkout

- run:
name: Install Packages

command: |
apk update
sh scripts/install/bash.sh $BLOG_BUILD_ENV
bash scripts/install/make.sh
make install-git env=$BLOG_BUILD_ENV
npm install -g bats

- run:
name: Add Git Submodules
command: make git-submodules env=$BLOG_BUILD_ENV

- run:
name: Run Node Tests
command: bats tests/_.bats tests/install-node.bats


workflows:
test:
when: << pipeline.parameters.run-tests-jobs >>

jobs:
- tests-bats
- tests-node
5 changes: 5 additions & 0 deletions .docker/bats.alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM bats/bats:1.7.0

LABEL maintainer="Airscript <[email protected]>"

COPY . .
17 changes: 17 additions & 0 deletions .docker/bats.node.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:18.7.0-alpine3.16

LABEL maintainer="Airscript <[email protected]>"

ARG APP_DIR=app

RUN \
apk update && \
apk add bash && \
npm install -g bats \
mkdir ${APP_DIR}

WORKDIR /${APP_DIR}

COPY . .

ENTRYPOINT ["bash", "bats"]
3 changes: 2 additions & 1 deletion .docker/blog.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ARG BLOG_BUILD_ENV=docker
RUN \
apk update && \
apk add hugo && \
apk add bash && \
mkdir ${BLOG_DIR}

WORKDIR /${BLOG_DIR}
Expand All @@ -25,4 +26,4 @@ ENTRYPOINT ["./scripts/docker-entrypoint.sh"]

CMD ["hugo"]

EXPOSE ${BLOG_PORT}
EXPOSE ${BLOG_PORT}
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
[submodule "themes/PaperMod"]
path = themes/PaperMod
url = https://github.com/adityatelange/hugo-PaperMod.git

[submodule "tests/bats"]
path = tests/bats
url = https://github.com/bats-core/bats-core.git

[submodule "tests/libraries/bats-support"]
path = tests/libraries/bats-support
url = https://github.com/bats-core/bats-support.git

[submodule "tests/libraries/bats-assert"]
path = tests/libraries/bats-assert
url = https://github.com/bats-core/bats-assert.git
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ all: build run
clean:
docker compose down
cd ./themes/PaperMod && find . -name "*" -delete
cd ./tests/bats && find . -name "*" -delete
cd ./tests/libraries/bats-assert && find . -name "*" -delete
cd ./tests/libraries/bats-support && find . -name "*" -delete

.PHONY: build
build: git-submodules
Expand All @@ -19,6 +22,38 @@ build: git-submodules
run:
docker compose up -d

.PHONY: all-test
all-test: build-test run-test

.PHONY: clean-test
clean-test:
docker rm worker-bats-node; \
docker rm worker-bats-alpine; \
docker rmi airscript/bats:node; \
docker rmi airscript/bats:alpine

.PHONY: clean-bats
clean-bats:
docker rmi bats/bats:1.7.0
docker rmi node:18.7.0-alpine3.16

.PHONY: build-test
build-test:
docker build -f .docker/bats.alpine.Dockerfile -t airscript/bats:alpine .
docker build -f .docker/bats.node.Dockerfile -t airscript/bats:node .

.PHONY: run-test
run-test:
docker run -it --rm --name="worker-bats-alpine" airscript/bats:alpine \
./tests/_.bats ./tests/install.bats ./tests/shared.bats

docker run -it --rm --name="worker-bats-node" airscript/bats:node \
./tests/_.bats ./tests/install-node.bats

.PHONY: install-bash
install-bash:
sh ./scripts/install/bash.sh

.PHONY: install-npm
install-npm:
sh ./scripts/install/npm.sh
Expand Down
2 changes: 0 additions & 2 deletions init.sh

This file was deleted.

2 changes: 2 additions & 0 deletions scripts/bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "Bats is working correctly."
2 changes: 1 addition & 1 deletion scripts/ci/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
#!/bin/bash
hugo --gc --minify
2 changes: 1 addition & 1 deletion scripts/ci/deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
#!/bin/bash
netlify deploy --site $1 --auth $2 --prod --dir=public
2 changes: 1 addition & 1 deletion scripts/ci/verify.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
if [ "$1" = "build" ]; then
apk --version

Expand Down
2 changes: 1 addition & 1 deletion scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e

if [ "$1" = 'hugo' ]; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/docker/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
#!/bin/bash
echo "Building Docker image..."
docker build -f .docker/blog.Dockerfile -t airscript/blog:$1 .
2 changes: 1 addition & 1 deletion scripts/docker/login.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
#!/bin/bash
echo "Logging into Docker Hub..."
docker login --username $1 --password $2
2 changes: 1 addition & 1 deletion scripts/docker/push.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
#!/bin/bash
echo "Pushing image to Docker Hub..."
docker push airscript/blog:$1
4 changes: 4 additions & 0 deletions scripts/install/bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
apk add bash
bash --version
echo "Bash installed successfully."
4 changes: 3 additions & 1 deletion scripts/install/docker-cli.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/bin/sh
#!/bin/bash
apk add docker-cli
docker --version
echo "Docker CLI installed successfully."
6 changes: 5 additions & 1 deletion scripts/install/git.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/sh
#!/bin/bash
if [ ! "$1" = "compose" ]; then
apk add git
echo "Git installed successfully."

else
echo "Git installation has been skipped."
fi
3 changes: 2 additions & 1 deletion scripts/install/hugo.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
#!/bin/bash
apk add hugo
echo "Hugo installed successfully."
3 changes: 2 additions & 1 deletion scripts/install/make.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
#!/bin/bash
apk add make
echo "Make installed successfully."
3 changes: 2 additions & 1 deletion scripts/install/netlify-cli.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
#!/bin/bash
npm install -g netlify-cli
echo "Netlify CLI installed successfully."
3 changes: 2 additions & 1 deletion scripts/install/npm.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
#!/bin/bash
npm install -g npm
echo "npm installed successfully."
Loading