Skip to content

Commit

Permalink
Merge pull request #3 from voxpupuli/make_it_work
Browse files Browse the repository at this point in the history
feat: add container ci, build and docu
  • Loading branch information
rwaffen authored Nov 8, 2024
2 parents 0f4f3b9 + d86c005 commit 88df7fe
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 58 deletions.
28 changes: 28 additions & 0 deletions .commitlintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# The rules below have been manually copied from @commitlint/config-conventional
# and match the v1.0.0 specification:
# https://www.conventionalcommits.org/en/v1.0.0/#specification
#
# You can remove them and uncomment the config below when the following issue is
# fixed: https://github.com/conventional-changelog/commitlint/issues/613
#
# extends:
# - '@commitlint/config-conventional'
rules:
body-leading-blank: [1, always]
body-max-line-length: [2, always, 100]
footer-leading-blank: [1, always]
footer-max-line-length: [2, always, 100]
header-max-length: [2, always, 100]
subject-case:
- 2
- never
- [sentence-case, start-case, pascal-case, upper-case]
subject-empty: [2, never]
subject-full-stop: [2, never, "."]
type-case: [2, always, lower-case]
type-empty: [2, never]
type-enum:
- 2
- always
- [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]
49 changes: 49 additions & 0 deletions .github/workflows/build_container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Build and publish a 🛢️ container

on:
push:
branches:
- 'main'
tags:
- '*'
workflow_dispatch:

jobs:
build-and-push-container:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Source checkout
uses: actions/checkout@v4

- name: Get commitlint version
id: get_version
run: echo "cl_version="$(jq -r '.dependencies."@commitlint/cli"' package.json | sed 's/\^//') >> $GITHUB_OUTPUT

# Parse ref_name and if it is main, change it to latest
- name: Set tag
id: set_tag
run: echo "tag=$(echo ${{ github.ref_name }} | sed 's/^main$/latest/')" >> $GITHUB_OUTPUT

- name: Build Vox Pupuli commitlint container
uses: voxpupuli/gha-build-and-publish-a-container@v2
with:
registry_password: ${{ secrets.GITHUB_TOKEN }}
build_arch: linux/amd64,linux/arm64
docker_username: voxpupulibot
docker_password: ${{ secrets.DOCKERHUB_BOT_PASSWORD }}
tags: |
ghcr.io/voxpupuli/commitlint:${{ steps.get_version.outputs.cl_version }}-${{ steps.set_tag.outputs.tag }}
ghcr.io/voxpupuli/commitlint:latest
docker.io/voxpupuli/commitlint:${{ steps.get_version.outputs.cl_version }}-${{ steps.set_tag.outputs.tag }}
docker.io/voxpupuli/commitlint:latest
- name: Update Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: voxpupulibot
password: ${{ secrets.DOCKERHUB_BOT_PASSWORD }}
repository: voxpupuli/commitlint
59 changes: 59 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
name: CI🚦

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
general_ci:
uses: voxpupuli/crafty/.github/workflows/general_ci.yaml@main
with:
shellcheck_scan_dir: '.'

build_test_container:
name: 'Build test container'
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build image
uses: docker/build-push-action@v6
with:
tags: 'ci/test:${{ github.event.number }}'
push: false

tests:
needs:
- build_test_container
runs-on: ubuntu-latest
name: Test suite
steps:
- run: echo Test suite completed

dependabot:
permissions:
contents: write
name: 'Dependabot auto-merge'
needs:
- tests
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.2.0
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'

- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
43 changes: 43 additions & 0 deletions .github/workflows/security_scanning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
name: Security Scanning 🕵️

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build_test_container:
name: 'Build test container'
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build local container
uses: docker/build-push-action@v6
with:
tags: 'ci/test:latest'
push: false

- name: Scan image with Anchore Grype
uses: anchore/scan-action@v5
id: scan
with:
image: 'ci/test:latest'
fail-build: false

- name: Inspect action SARIF report
run: jq . ${{ steps.scan.outputs.sarif }}

- name: Upload Anchore scan SARIF report
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
78 changes: 39 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
FROM node:23.1.0-alpine3.20 AS build

WORKDIR /npm
COPY package.json /npm

RUN npm install

###############################################################################

FROM node:23.1.0-alpine3.20 AS final

LABEL org.label-schema.maintainer="Voxpupuli Team <voxpupuli@groups.io>" \
org.label-schema.vendor="Voxpupuli" \
org.label-schema.url="https://github.com/voxpupuli/container-commitlint" \
org.label-schema.name="Vox Pupuli Container for commitlint" \
org.label-schema.license="AGPL-3.0-or-later" \
org.label-schema.vcs-url="https://github.com/voxpupuli/container-commitlint" \
org.label-schema.schema-version="1.0" \
org.label-schema.dockerfile="/Dockerfile"

COPY Dockerfile /
COPY docker-entrypoint.sh /
COPY docker-entrypoint.d /docker-entrypoint.d
COPY --from=build /npm /npm

RUN apk update && apk upgrade \
&& apk add --no-cache --update bash git \
&& chmod +x /docker-entrypoint.sh
# && chmod +x /docker-entrypoint.d/*.sh

# fix ENOGITREPO Not running from a git repository.
RUN git config --global --add safe.directory '*'

WORKDIR /data

ENV PATH="$PATH:/npm/node_modules/.bin"
ENV NODE_OPTIONS="--use-openssl-ca"

ENTRYPOINT [ "/docker-entrypoint.sh" ]
FROM node:23.1.0-alpine3.20 AS build

WORKDIR /npm
COPY package.json /npm

RUN npm install

###############################################################################

FROM node:23.1.0-alpine3.20 AS final

LABEL org.label-schema.maintainer="Voxpupuli Team <voxpupuli@groups.io>" \
org.label-schema.vendor="Voxpupuli" \
org.label-schema.url="https://github.com/voxpupuli/container-commitlint" \
org.label-schema.name="Vox Pupuli Container for commitlint" \
org.label-schema.license="AGPL-3.0-or-later" \
org.label-schema.vcs-url="https://github.com/voxpupuli/container-commitlint" \
org.label-schema.schema-version="1.0" \
org.label-schema.dockerfile="/Dockerfile"

COPY Dockerfile /
COPY docker-entrypoint.sh /
COPY docker-entrypoint.d /docker-entrypoint.d
COPY --from=build /npm /npm

RUN apk update && apk upgrade \
&& apk add --no-cache --update bash git \
&& chmod +x /docker-entrypoint.sh \
# fix ENOGITREPO Not running from a git repository.
&& git config --global --add safe.directory '*'
# && chmod +x /docker-entrypoint.d/*.sh

WORKDIR /data

ENV PATH="$PATH:/npm/node_modules/.bin"
ENV NODE_OPTIONS="--use-openssl-ca"

ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "--last" ]
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,70 @@
# Vox Pupuli Commitlint Container

[![CI](https://github.com/voxpupuli/container-commitlint/actions/workflows/ci.yaml/badge.svg)](https://github.com/voxpupuli/container-commitlint/actions/workflows/ci.yaml)
[![License](https://img.shields.io/github/license/voxpupuli/container-commitlint.svg)](https://github.com/voxpupuli/container-commitlint/blob/main/LICENSE)
[![Sponsored by betadots GmbH](https://img.shields.io/badge/Sponsored%20by-betadots%20GmbH-blue.svg)](https://www.betadots.de)

This container can be used to lint commits.
It encapsulates [commitlint](https://github.com/conventional-changelog/commitlint) and all necessary plugins.
See [package.json](package.json) for details. This is a npm application running in an alpine container.

## Usage

### Lint last commit only

```shell
podman run -it --rm -v $PWD:/data ghcr.io/voxpupuli/commitlint:latest
# or (but thats the default)
podman run -it --rm -v $PWD:/data ghcr.io/voxpupuli/commitlint:latest --last
```

### Lint all commits from a branch

```shell
podman run -it --rm -v $PWD:/data ghcr.io/voxpupuli/commitlint:latest \
--from $(git merge-base $(git symbolic-ref refs/remotes/origin/HEAD --short) HEAD) \
--to HEAD
```

### More options

For more options see:

```shell
podman run -it --rm -v $PWD:/data ghcr.io/voxpupuli/commitlint:latest --help
```

### Example commitlint config

See [.commitlint.yaml](.commitlintrc.yaml)

```yaml
---
# The rules below have been manually copied from @commitlint/config-conventional
# and match the v1.0.0 specification:
# https://www.conventionalcommits.org/en/v1.0.0/#specification
#
# You can remove them and uncomment the config below when the following issue is
# fixed: https://github.com/conventional-changelog/commitlint/issues/613
#
# extends:
# - '@commitlint/config-conventional'
rules:
body-leading-blank: [1, always]
body-max-line-length: [2, always, 100]
footer-leading-blank: [1, always]
footer-max-line-length: [2, always, 100]
header-max-length: [2, always, 100]
subject-case:
- 2
- never
- [sentence-case, start-case, pascal-case, upper-case]
subject-empty: [2, never]
subject-full-stop: [2, never, "."]
type-case: [2, always, lower-case]
type-empty: [2, never]
type-enum:
- 2
- always
- [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]
```
19 changes: 0 additions & 19 deletions commitlint.config.js

This file was deleted.

0 comments on commit 88df7fe

Please sign in to comment.