Skip to content
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

Support for shellcheck and verify generated project. #15

Merged
merged 3 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,30 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: 3.9
- run: python -m pip install cookiecutter pytest
- run: python -m pip install cookiecutter pytest pyyaml
- run: pytest

lint-workflows:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
- run: python -m pip install cookiecutter
- run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
- name: Generate project
run: |
cookiecutter --config-file tests/context.yaml --no-input .
escaped marked this conversation as resolved.
Show resolved Hide resolved
cd example-project/
# actionlint needs a git repo in place
git init
git config user.email "gha@users.noreply.github.com"
git config user.name "gha"
git add .
git commit -m "initial commit"
- name: Lint workflows
escaped marked this conversation as resolved.
Show resolved Hide resolved
run: |
cd example-project
../actionlint -color
6 changes: 6 additions & 0 deletions tests/context.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
default_context:
author_name: "John Doe"
author_email: "john.doe@mail.com"
github_username: "johndoe"
project_name: "example-project"
project_short_description: "A short description of the project"
14 changes: 6 additions & 8 deletions tests/test_project_generation.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import yaml
from pathlib import Path

from cookiecutter.main import cookiecutter

TEMPLATE_DIR = str(Path(__file__).parent.parent)
CONTEXT_FILE = Path(__file__).parent / "context.yaml"

PROJECT_NAME = "example-project"
with open(CONTEXT_FILE) as file_handler:
content = yaml.safe_load(file_handler)

EXAMPLE_CONTEXT = {
"author_name": "John Doe",
"author_email": "john.doe@mail.com",
"github_username": "johndoe",
"project_name": PROJECT_NAME,
"project_short_description": "A short description of the project",
}
EXAMPLE_CONTEXT = content['default_context']
PROJECT_NAME = EXAMPLE_CONTEXT["project_name"]


def test_generate_new_project(tmp_path):
Expand Down
14 changes: 8 additions & 6 deletions {{cookiecutter.project_slug}}/.github/workflows/cookiecutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ jobs:
if: steps.changes.outputs.changed == 1
shell: bash
run: |
echo ::set-output name=current_version::$(git show HEAD:.cruft.json | jello -r "_['commit'][:8]")
echo ::set-output name=next_version::$(cat .cruft.json | jello -r "_['commit'][:8]")
CURRENT_VERSION=$(git show HEAD:.cruft.json | jello -r "_['commit'][:8]")
NEXT_VERSION=$(jello -r "_['commit'][:8]" < .cruft.json)
echo ::set-output name="current_version::$CURRENT_VERSION"
echo ::set-output name="next_version::$NEXT_VERSION"

- name: Get changelog
id: get_changelog
if: steps.changes.outputs.changed == 1
shell: bash
run: |
export TEMPLATE=$(cat .cruft.json | jello -r "_['template']")
git clone $TEMPLATE /tmp/template
TEMPLATE=$(jello -r "_['template']" < .cruft.json)
git clone "$TEMPLATE" /tmp/template
cd /tmp/template
body=$((echo "Date;Change;Hash"; git log --pretty=format:"%as;%s;%h" ${{ steps.get_versions.outputs.current_version }}..${{ steps.get_versions.outputs.next_version }}) | tabulate --header --format github -s ';' -)
body=$( (echo "Date;Change;Hash"; git log --pretty=format:"%as;%s;%h" ${{ steps.get_versions.outputs.current_version }}..${{ steps.get_versions.outputs.next_version }}) | tabulate --header --format github -s ';' -)
body=$(cat <<EOF
Changes from $TEMPLATE

Expand All @@ -58,7 +60,7 @@ jobs:
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=changelog::$body
echo ::set-output name="changelog::$body"

# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
- name: Create Pull Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
id: check_for_outdated_dependencies
run: |
body=$(poetry show -o -n)
echo ::set-output name=body::$body
echo ::set-output name="body::$body"

- name: Format PR message
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
Expand All @@ -35,7 +35,7 @@ jobs:
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
echo ::set-output name="body::$body"

- name: Update outdated packages
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
poetry version ${{ github.event.inputs.version }}
version=$(poetry version --short)
echo ::set-output name=version::$version
echo ::set-output name="version::$version"
- name: Update changelog
id: changelog
shell: bash
Expand All @@ -31,7 +31,7 @@ jobs:
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
echo ::set-output name="body::$body"
- name: Commit changes
uses: EndBug/add-and-commit@v7
with:
Expand Down