Skip to content

Commit

Permalink
feat: init repository (#2)
Browse files Browse the repository at this point in the history
# Description

First initialization of all templates used to build a Docker project.

# Verification

This feature branch only.
  • Loading branch information
kayman-mk authored May 14, 2024
1 parent 369c67c commit 27398ef
Show file tree
Hide file tree
Showing 27 changed files with 592 additions and 1 deletion.
54 changes: 54 additions & 0 deletions .config/cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"version": "0.2",
"language": "en",
"words": [
"cpus",
"Hapag",
"Infracost",
"javadoc",
"javadocs",
"oidc",
"Repology",
"sonatype",
"tflint",
"tfsec"
],
"ignoreWords": [
"Buildx",
"DOCKERHUB",
"amannn",
"aquasecurity",
"automerge",
"automerged",
"buildcache",
"buildx",
"codeowners",
"codeql",
"conventionalcommits",
"datasource",
"dorny",
"hadolint",
"hlag",
"hmarr",
"ibiqlik",
"kayma",
"kayman",
"ludeeus",
"markdownlint",
"mktemp",
"nullglob",
"ossrh",
"pascalfrenz",
"releaserc",
"rhysd",
"ruleset",
"sarif",
"shellcheck",
"shuf",
"shunsuke",
"signoff",
"temurin",
"tfstate",
"vuln"
]
}
12 changes: 12 additions & 0 deletions .config/markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# Default state for all rules
default: true

# MD013/line-length - Line length
MD013:
# Number of characters
line_length: 132
# Number of characters for headings
heading_line_length: 132
# Number of characters for code blocks
code_block_line_length: 132
8 changes: 8 additions & 0 deletions .config/yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
extends: default

rules:
line-length:
max: 132
comments:
min-spaces-from-content: 1 # Renovate uses 1 space only
21 changes: 21 additions & 0 deletions .github/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: fix-byte-order-marker
- id: check-added-large-files
args:
- "--maxkb=20"
- id: check-case-conflict
- id: check-yaml
- id: check-json
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.0
hooks:
- id: prettier
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* @hapag-lloyd/organization-defaults

# license file shouldn't be changed and needs to be reviewed by lawyers
LICENSE @hapag-lloyd/organization-defaults
25 changes: 25 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contribution guide

We appreciate your thought to contribute to open source. :heart: We want to make contributing as easy as possible. You are welcome to:

- Report a bug
- Discuss the current state of the code
- Submit a fix
- Propose new features

We use [Github Flow](https://guides.github.com/introduction/flow/index.html), so all code changes happen through pull
requests. We actively welcome your pull requests:

1. Fork the repo and create your branch from `main`.
2. If you've added code, check one of the examples.
3. Make sure your code lints.
4. Raise a pull request.

## Documentation

We use [pre-commit](https://pre-commit.com/) for some default checks which are fast and find the most common errors.

## License

By contributing, you agree that your contributions will be licensed under the license available at
[LICENSE](blob/main/LICENSE).
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Found a bug? Report it!
title: ''
labels: new, bug
assignees: ''
---

<!-- Before submitting a bug, make sure that you meet the following requirements:
1. use the latest version of the module
2. read the documentation
-->

# Describe the bug

A clear and concise description of what the bug is.

# To Reproduce

Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

# Expected behavior

A clear and concise description of what you expected to happen.

# Additional context

Add any other context about the problem here.
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Feature Request
about: Propose a new feature
title: ''
labels: new, enhancement
assignees: ''
---

# Describe the solution you'd like

<!--
Provide a clear and concise description of what you want to happen. Add some sentences to describe the use case
to be solved by this feature.
-->

# Describe alternatives you've considered

<!--
Let us know about other solutions you've tried or researched.
-->

# Suggest a solution

<!--
Things to include:
- details of the technical implementation
- tradeoffs made in design decisions
-caveats and considerations for the future
If there are multiple solutions, please present each one separately. Save comparisons for the very end.
-->

# Additional context

<!--
Is there anything else you can add about the proposal?
You might want to link to related issues here, if you haven't already.
-->
21 changes: 21 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Description

What is the overall goal of your PR? Which problem does it solve? Please also include relevant motivation and context.
List any dependencies that are required for this change.

Fixes #(issue number)

# Migrations required

yes: please describe the migration
no: please delete the whole paragraph

# Verification

Please describe the test cases you used to verify your code. Did you check the change in your environment?

# Checklist

- [ ] My code follows the style guidelines of the project
- [ ] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation
4 changes: 4 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
$schema: "https://docs.renovatebot.com/renovate-schema.json",
extends: ["github>Hapag-Lloyd/Renovate-Global-Configuration"],
}
16 changes: 16 additions & 0 deletions .github/update_init_branches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail

#
# This script rebases all init branches on the main branch.
#

git checkout main
git pull

# for all init branches
for branch in $(git branch --list "init-*"); do
git checkout "$branch"
git merge main
git push
done
109 changes: 109 additions & 0 deletions .github/update_templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env bash
set -euo pipefail

#
# This script updates the current repository with the latest version of the templates. It creates a new branch and a pull request.
#

function ensure_dependencies_or_exit() {
if ! command -v gh &> /dev/null; then
echo "gh is not installed. Please install it from https://cli.github.com/"
exit 1
fi
}

function ensure_repo_preconditions_or_exit() {
# ensure main branch
if [ "$(git branch --show-current)" != "main" ]; then
echo "The current branch is not main. Please switch to the main branch."
exit 1
fi

# ensure a clean working directory
if [ -n "$(git status --porcelain)" ]; then
echo "The working directory is not clean. Please use a clean copy so no unintended changes are merged."
exit 1
fi
}

function create_and_show_pr_for_init_branch() {
local branch_name=$1

if git branch | grep -q "$branch_name"; then
git checkout "$branch_name"

title=$(head -n1 pr-description.md)
body=$(tail -n2 pr-description.md)

rm pr-description.md
git add .
git commit -m "remove the PR description"
git push

gh pr create --title "$title" --body "$body" --base main --head "$branch_name"
gh pr view --web
fi
}

ensure_dependencies_or_exit
ensure_repo_preconditions_or_exit

latest_template_path=$(mktemp -d -t repository-template-XXXXX)
new_branch_name=$(basename "$latest_template_path")

# clone the default branch to get the latest version of the template files
gh repo clone https://github.com/Hapag-Lloyd/Repository-Template-Maven.git "$latest_template_path"

# create a new branch to update the templates
git checkout -b "$new_branch_name"

# update issue templates
cp -r "$latest_template_path/.github/ISSUE_TEMPLATE" .github/

# update pull request template
cp "$latest_template_path/.github/PULL_REQUEST_TEMPLATE.md" .github/

# update contributing guidelines
cp "$latest_template_path/.github/CONTRIBUTING.md" .github/

# update the update scripts
cp "$latest_template_path/.github"/update_*.sh .github/

# create a commit, push it and open a pull request
git add .github
git commit -m "chore: update project templates"
git push --set-upstream origin "$new_branch_name"

gh pr create --title "chore: update project templates" --body "This PR updates the project templates." --base main --head "$new_branch_name"

echo "The project templates have been updated. Please review and merge the pull request."
gh pr view --web

# create PR to initialize the CODEOWNERS file
branch_name="kayma/init-codeowners"

if git branch | grep -q "$branch_name"; then
git checkout "$branch_name"

title=$(head -n1 pr-description.md)
body=$(tail -n2 pr-description.md)

rm pr-description.md
git add .
git commit -m "remove the PR description"
git push

gh pr create --title "$title" --body "$body" --base main --head "$branch_name"
gh pr view --web
fi

# initialize the LICENSE and CODEOWNERS file

# find all init- branches
init_branches=$(git branch | grep "init-")

for init_branch in $init_branches; do
create_and_show_pr_for_init_branch "$init_branch"
done

rm -rf "$latest_template_path"
Loading

0 comments on commit 27398ef

Please sign in to comment.