Skip to content

Commit

Permalink
ci: better ci and other project related stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Tomer Figenblat <[email protected]>
  • Loading branch information
TomerFi committed Feb 6, 2024
1 parent 59c3541 commit 5e4d19a
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 365 deletions.
18 changes: 0 additions & 18 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
# editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[**.{yaml,yml}]
indent_style = space
indent_size = 2
max_line_length = 100
trim_trailing_whitespace = true

[**.md]
max_line_length = 120
trim_trailing_whitespace = false

[**.{sh,bash,zsh,csh,ksh,fish}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[Makefile*]
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
6 changes: 4 additions & 2 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
root: true
parserOptions:
ecmaVersion: 2022
sourceType: module
ecmaVersion: latest
env:
node: true
commonjs: true
mocha: true
shelljs: true
extends:
- "eslint:recommended"
- "plugin:editorconfig/all"
Expand Down
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ updates:
include: "scope"
assignees:
- "tomerfi"

- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
labels:
- "type: dependencies"
commit-message:
prefix: "build"
include: "scope"
assignees:
- "tomerfi"
91 changes: 50 additions & 41 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,72 @@ on:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
pull-requests: read

jobs:
lint:
runs-on: ubuntu-latest
name: Lint project
permissions:
pull-requests: write
code:
strategy:
matrix:
node: ['20', 'latest']
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
name: "Test project { os: ${{ matrix.os }}, node: ${{ matrix.node }} }"
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
fetch-depth: 0
node-version: ${{ matrix.node }}
cache: npm

# required for testing
- name: Configure git
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- name: Lint sources
uses: docker://ghcr.io/github/super-linter:slim-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: false
IGNORE_GITIGNORED_FILES: true
IGNORE_GENERATED_FILES: true
VALIDATE_DOCKERFILE: true
VALIDATE_EDITORCONFIG: true
VALIDATE_GITHUB_ACTIONS: true
VALIDATE_MARKDOWN: true
VALIDATE_SHELL_SHFMT: true
VALIDATE_YAML: true
- name: Install project modules
run: npm ci

build:
- name: Lint source files
run: npm run lint

- name: Run unit tests
run: npm test

image:
runs-on: ubuntu-latest
needs: [lint]
name: Build docker image
permissions:
pull-requests: read
needs: [code]
name: Test container image
env:
TESTING_TAG: tomerfi/version-bumper:testing
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup Docker Buildx
uses: docker/[email protected]
- name: Setup docker buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
- name: Cache image layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '.dockerignore') }}
key: ${{ runner.os }}-image-layers-${{ hashFiles('Dockerfile') }}

- name: Build docker image (no push)
uses: docker/build-push-action@v5.1.0
- name: Build image
uses: docker/build-push-action@v5
with:
context: .
build-args: |
VCS_REF=${{ github.sha }}
BUILD_DATE=$(date +'%Y-%m-%d')
VERSION=testing
tags: tomerfi/version-bumper:testing
tags: ${{ env.TESTING_TAG }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
load: true

- name: Delete docker image
run: docker image rm tomerfi/version-bumper:testing
- name: Test image run
run: |
pattern='^version-bumper ([0-9]\.){2}[0-9](.+)?$'
sut=$(docker run --rm ${{ env.TESTING_TAG }} -v)
[[ $sut =~ $pattern ]] || exit 1
109 changes: 60 additions & 49 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,93 +8,104 @@ on:
description: "Release title"
required: false

env:
PLATFORMS: linux/amd64,linux/arm/v7,linux/arm64/v8

jobs:
release:
runs-on: ubuntu-latest
environment: deployment
name: Build, publish, release, and announce
name: Publish and Release
steps:
- name: Source checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ssh-key: ${{ secrets.DEPLOY_KEY }}

- name: Install node 20
uses: actions/setup-node@v3
with:
node-version: 20
cache: npm

- name: Setup QEMU
uses: docker/[email protected]
- name: Configure git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3.0.0
- name: Setup qemu
uses: docker/setup-qemu-action@v3

- name: Cache Docker layers
- name: Setup docker buildx
uses: docker/setup-buildx-action@v3

- name: Cache image layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '.dockerignore') }}
key: ${{ runner.os }}-image-layers-${{ hashFiles('Dockerfile') }}

- name: Login to Docker Hub
uses: docker/login-action@v3.0.0
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Setup Node
uses: actions/[email protected]
with:
node-version: 16

- name: Install global node modules
run: >
npm i -g
conventional-changelog-cli
conventional-changelog-conventionalcommits
conventional-recommended-bump
git-semver-tags
- name: Eat own dogfood
id: version_info
run: echo "next_version=$(bash entrypoint.sh | cut -f1 -d' ')" >> "$GITHUB_OUTPUT"

- name: Build images and push to Docker Hub
uses: docker/[email protected]
with:
context: .
push: true
platforms: ${{ env.PLATFORMS }}
tags: |
tomerfi/version-bumper:latest
tomerfi/version-bumper:${{ steps.version_info.outputs.next_version }}
build-args: |
VCS_REF=${{ github.sha }}
BUILD_DATE=$(date +'%Y-%m-%d')
VERSION=${{ steps.version_info.outputs.next_version }}
cache-from: |
type=local,src=/tmp/.buildx-cache
ghcr.io/tomerfi/version-bumper:early-access
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Install project modules
run: npm ci --production

- name: Decide new version
id: bump
run: echo "version=$(node src/cli.js | jq '.next')" >> "$GITHUB_OUTPUT"

- name: Create a release name
- name: Update package version
run: npm version ${{ steps.bump.outputs.version }} --no-git-tag-version

- name: Push new version
run: |
git add package.json package-lock.json
git commit -m "build: updated package with ${{ steps.bump.outputs.version }} [skip ci]"
git push
- name: Push new tag
run: |
git tag ${{ steps.bump.outputs.version }} -m "${{ steps.bump.outputs.version }}"
git push origin ${{ steps.bump.outputs.version }}
- name: Set a release name
id: release_name
uses: actions/github-script@v7
with:
script: |
var retval = '${{ steps.version_info.outputs.next_version }}'
var retval = ${{ steps.bump.outputs.version }}
if ('${{ github.event.inputs.title }}') {
retval = retval.concat(' - ${{ github.event.inputs.title }}')
}
core.setOutput('value', retval)
- name: Create a release
id: gh_release
uses: actions/github-script@v7
with:
script: |
const repo_name = context.payload.repository.full_name
const response = await github.request('POST /repos/' + repo_name + '/releases', {
tag_name: '${{ steps.version_info.outputs.next_version }}',
tag_name: '${{ steps.bump.outputs.version }}',
name: '${{ steps.release_name.outputs.value }}',
generate_release_notes: true
})
core.setOutput('html_url', response.data.html_url)
- name: Publish package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish

- name: Push image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
tags: |
tomerfi/version-bumper:latest
tomerfi/version-bumper:${{ steps.bump.outputs.version }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
Loading

0 comments on commit 5e4d19a

Please sign in to comment.