Skip to content

Commit

Permalink
fix: setup failing because inexisting function
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Oct 24, 2024
1 parent fb3da4a commit 92946e0
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 32 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ jobs:
run: ./bashdep.sh

- name: Run Tests
run: ./lib/bashunit --parallel `git ls-files "tests/*.sh"`
run: |
./lib/bashunit --parallel tests/first_time_setup/unit/**/*.sh
bash tests/first_time_setup/e2e/test_e2e.sh
release:
runs-on: ubuntu-22.04
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

# Example Entry

Example entry for a change in the project.

<!-- version list -->

## v0.1.0 (2024-10-23)

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# OpenFisca Setup Builder

<img width="821" alt="Screenshot 2024-10-22 at 18 01 25" src="https://github.com/user-attachments/assets/f89f3bb9-f752-466e-bff8-e192b264c3e3">

## Writing the Legislation

Example section for writing the legislation.
15 changes: 10 additions & 5 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ vars:
sh: git ls-files "*.yaml" "*.yml"
SH:
sh: git ls-files "*.sh"
SH_TEST:
sh: git ls-files "tests/*.sh"
UNIT_TESTS:
sh: git ls-files "tests/first_time_setup/unit/*.sh"
E2E_TESTS:
sh: git ls-files "tests/first_time_setup/e2e/*.sh"

tasks:
uninstall:
Expand Down Expand Up @@ -52,7 +54,10 @@ tasks:
test:
desc: Test the library.
vars:
SH_TEST:
ref: .SH_TEST | splitLines | join " "
UNIT_TESTS:
ref: .UNIT_TESTS | splitLines | join " "
E2E_TESTS:
ref: .E2E_TESTS | splitLines | join " "
cmds:
- lib/bashunit --parallel --simple {{.SH_TEST}}
- lib/bashunit --parallel --simple {{.UNIT_TESTS}}
- bash {{.E2E_TESTS}}
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ build_command = "pip install shfmt-py && TERM=xterm-256color ./build.sh"
tag_format = "{version}"
version_toml = [ "pyproject.toml:tool.poetry.version" ]
version_variables = [ "src/first_time_setup/messages.sh:version" ]

[tool.semantic_release.changelog]
mode = "update"
43 changes: 18 additions & 25 deletions src/first_time_setup/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,41 +155,37 @@ main() {
# Initialise the repository.
if ! "${ci}" || "${dry}"; then
echo ''
if "${dry}"; then colour::warn "$(msg::dry_mode)"; fi
colour::pass 'Initialise git repository...'
if ! "${dry}"; then
setup::init_repository "${ROOT_DIR}" "${label}" "${first_commit}"
else
colour::warn 'Skipping git repository initialisation because of dry run'
fi
setup::first_commit "${ROOT_DIR}" "${label}" "${first_commit}" "${dry}"
colour::pass "Commit made to 'main' with message:"
colour::logs "${first_commit}"
fi

# And go on...
if "${dry}"; then colour::warn "$(msg::dry_mode)"; fi
colour::pass 'Replace default extension_template references'
local -r files=$(git ls-files "src/${module}")
setup::replace_references "${label}" "${snake}" "${name}" "${files}"
setup::replace_references "${label}" "${snake}" "${name}" "${files}" "${dry}"
if "${dry}"; then colour::warn "$(msg::dry_mode)"; fi
colour::pass 'Remove bootstrap instructions'
setup::remove_bootstrap_instructions "${lineno_readme}"
setup::remove_bootstrap_instructions "${lineno_readme}" "${dry}"
if "${dry}"; then colour::warn "$(msg::dry_mode)"; fi
colour::pass 'Prepare README.md and CONTRIBUTING.md'
setup::prepare_readme_contributing "${url}"
setup::prepare_readme_contributing "${url}" "${dry}"
if "${dry}"; then colour::warn "$(msg::dry_mode)"; fi
colour::pass 'Prepare CHANGELOG.md'
setup::prepare_changelog "${lineno_changelog}"
setup::prepare_changelog "${lineno_changelog}" "${dry}"
if "${dry}"; then colour::warn "$(msg::dry_mode)"; fi
colour::pass 'Prepare pyproject.toml'
setup::prepare_pyproject "${url}" "${folder}"
setup::prepare_pyproject "${url}" "${folder}" "${dry}"
if "${dry}"; then colour::warn "$(msg::dry_mode)"; fi
colour::pass 'Rename package to:'
colour::logs "${package}"
if ! "${dry}"; then
setup::rename_package "${package}"
else
colour::warn 'Skipping renaming of package because of dry run'
fi
setup::rename_package "${package}" "${dry}"
if "${dry}"; then colour::warn "$(msg::dry_mode)"; fi
colour::pass 'Remove single use first time setup files'
if ! "${dry}"; then
setup::remove_files
else
colour::warn 'Skipping removal of first time setup files because of dry run'
fi
setup::remove_files "${dry}"

# Committing and tagging take directly place in the GitHub Actions workflow.
if "${ci}"; then
Expand All @@ -200,12 +196,9 @@ main() {
fi

# Second commit and first tag.
if "${dry}"; then colour::warn "$(msg::dry_mode)"; fi
colour::pass 'Committing and tagging...'
if ! "${dry}"; then
setup::second_commit "${second_commit}"
else
colour::warn 'Skipping committing and tagging because of dry run'
fi
setup::second_commit "${second_commit}" "${dry}"
colour::pass "Second commit and first tag made on 'main' branch:"
colour::logs "${second_commit}"

Expand Down
7 changes: 7 additions & 0 deletions src/first_time_setup/messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ Bootstrap complete, you can now push this codebase to your remote repository.
'cd ../openfisca-${1} to navigate to it.
MSG
}

# @description Define the message for when running in dry mode.
msg::dry_mode() {
cat <<MSG
»skipping the next step as we are running in dry mode«
MSG
}
18 changes: 18 additions & 0 deletions src/first_time_setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ setup::changelog_lineno() {
# @arg $1 The parent folder.
# @arg $2 The setup name label.
# @arg $3 The first commit message.
# @arg $4 If we are running in dry mode.
setup::first_commit() {
if "${4:-false}"; then return; fi
cd ..
mv "${1}" openfisca-"${2}"
cd openfisca-"${2}"
Expand All @@ -62,7 +64,9 @@ setup::first_commit() {
# @arg $2 The jurisdiction snake cased.
# @arg $3 The normal jurisdiction name.
# @arg $4 The list of files to replace.
# @arg $5 If we are running in dry mode.
setup::replace_references() {
if "${5:-false}"; then return; fi
sed -i.template "s|openfisca-extension_template|openfisca-${1}|g" \
README.md Taskfile.yaml pyproject.toml CONTRIBUTING.md
# shellcheck disable=SC2086
Expand All @@ -75,30 +79,38 @@ setup::replace_references() {

# @description Remove bootstrap instructions.
# @arg $1 The last line number of the bootstrapping section in the README.md.
# @arg $2 If we are running in dry mode.
setup::remove_bootstrap_instructions() {
if "${2:-false}"; then return; fi
sed -i.template -e "3,${1}d" README.md
find . -name "*.template" -type f -delete
}

# @description Prepare README.md and CONTRIBUTING.md.
# @arg $1 The repository URL.
# @arg $2 If we are running in dry mode.
setup::prepare_readme_contributing() {
if "${2:-false}"; then return; fi
sed -i.template "s|https://example.com/repository|${1}|g" \
README.md CONTRIBUTING.md
find . -name "*.template" -type f -delete
}

# @description Prepare CHANGELOG.md.
# @arg $1 The last line number of the changelog section in the CHANGELOG.md.
# @arg $2 If we are running in dry mode.
setup::prepare_changelog() {
if "${2:-false}"; then return; fi
sed -i.template -e "1,${1}d" CHANGELOG.md
find . -name "*.template" -type f -delete
}

# @description Prepare pyproject.toml.
# @arg $1 The repository URL.
# @arg $2 The repository folder.
# @arg $3 If we are running in dry mode.
setup::prepare_pyproject() {
if "${3:-false}"; then return; fi
sed -i.template \
"s|https://github.com/openfisca/extension-template|${1}|g" \
pyproject.toml
Expand All @@ -110,12 +122,16 @@ setup::prepare_pyproject() {

# @description Rename the package.
# @arg $1 The new package name.
# @arg $2 If we are running in dry mode.
setup::rename_package() {
if "${2:-false}"; then return; fi
git mv openfisca_extension_template "${1}"
}

# Remove single use first time setup files
# @arg $1 If we are running in dry mode.
setup::remove_files() {
if "${1:-false}"; then return; fi
git rm .github/workflows/first-time-setup.yml &>/dev/null 2>&1
git rm bashdep.sh &>/dev/null 2>&1
git rm build.sh &>/dev/null 2>&1
Expand All @@ -126,7 +142,9 @@ setup::remove_files() {

# @description Second commit and first tag.
# @arg $1 The second commit message.
# @arg $2 If we are running in dry mode.
setup::second_commit() {
if "${2:-false}"; then return; fi
git add .
git commit --no-gpg-sign --quiet --message "${1}" \
--author='OpenFisca Bot <[email protected]>'
Expand Down
2 changes: 1 addition & 1 deletion src/first_time_setup/status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ status::check_continue() {
colour::pass 'Can the setup continue?'
colour::logs "${3}"
if "${4}"; then
colour::warn 'Persevering because the setup is being run in dry mode.'
colour::warn '»persevering because the setup is being run in dry mode«'
fi
else
colour::warn 'Can the setup continue?'
Expand Down
19 changes: 19 additions & 0 deletions tests/first_time_setup/e2e/test_e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -euo pipefail

declare -xr DRY_MODE=true
declare -xr JURISDICTION_NAME="L'Île-d'Yeu"
declare -xr REPOSITORY_URL='https://github.com/openfisca/openfisca-ile-d_yeu'

source 'src/first_time_setup/utils/colours.sh'

result=$(./first-time-setup.sh 2>&1 1>/dev/null)

if [[ -n "${result}" ]]; then
colour::fail 'First time setup failed with error:'
colour::logs "${result}"
exit 1
fi

colour::done 'First time setup ran successfully!'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 92946e0

Please sign in to comment.