Skip to content

Commit

Permalink
feat: add build script
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Oct 23, 2024
1 parent 2c06754 commit b666d65
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 22 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
git_committer_name: "OpenFisca Bot"
git_committer_email: "bot+${{ github.sha }}@openfisca.org"
id: release

- name: Upload to GitHub Release Assets
uses: python-semantic-release/[email protected]
if: steps.release.outputs.released == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.release.outputs.tag }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.python-version
.idea
.python-version
first-time-setup.sh
lib
61 changes: 40 additions & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,77 @@
# CHANGELOG


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

### Bug Fixes

* fix: do not depend on lib to decode ([`0c4a228`](https://github.com/openfisca/openfisca-setup-builder/commit/0c4a2284043c577af1fb9590383ce0d2abfd687a))
- fix: do not depend on lib to decode
([`0c4a228`](https://github.com/openfisca/openfisca-setup-builder/commit/0c4a2284043c577af1fb9590383ce0d2abfd687a))

* fix: correct string decoding order ([`8150786`](https://github.com/openfisca/openfisca-setup-builder/commit/8150786aa86d0968ea270bd0c2cef2f074747f52))
- fix: correct string decoding order
([`8150786`](https://github.com/openfisca/openfisca-setup-builder/commit/8150786aa86d0968ea270bd0c2cef2f074747f52))

### Build System

* build: add poetry ([`ebd7c96`](https://github.com/openfisca/openfisca-setup-builder/commit/ebd7c960a9b27dbb05c5ea646b4a26e35a70506d))
- build: add poetry
([`ebd7c96`](https://github.com/openfisca/openfisca-setup-builder/commit/ebd7c960a9b27dbb05c5ea646b4a26e35a70506d))

* build: add Taskfile.yaml ([`4275195`](https://github.com/openfisca/openfisca-setup-builder/commit/4275195f43d8ba7c715c21e676ab2e7e0cc1b100))
- build: add Taskfile.yaml
([`4275195`](https://github.com/openfisca/openfisca-setup-builder/commit/4275195f43d8ba7c715c21e676ab2e7e0cc1b100))

* build: add .shellcheck ([`772b2c6`](https://github.com/openfisca/openfisca-setup-builder/commit/772b2c6a129e9dbfa159c9e9dd88a8fb83b029a9))
- build: add .shellcheck
([`772b2c6`](https://github.com/openfisca/openfisca-setup-builder/commit/772b2c6a129e9dbfa159c9e9dd88a8fb83b029a9))

* build: add .yamllint ([`9f1e940`](https://github.com/openfisca/openfisca-setup-builder/commit/9f1e940ea7f70e468e29a8523039c6173201bd0b))
- build: add .yamllint
([`9f1e940`](https://github.com/openfisca/openfisca-setup-builder/commit/9f1e940ea7f70e468e29a8523039c6173201bd0b))

* build: add .gitignore ([`47eda3f`](https://github.com/openfisca/openfisca-setup-builder/commit/47eda3f16fe1ecb854ac284ab475f555c3875db3))
- build: add .gitignore
([`47eda3f`](https://github.com/openfisca/openfisca-setup-builder/commit/47eda3f16fe1ecb854ac284ab475f555c3875db3))

* build: add .editorconfig ([`ccc45c7`](https://github.com/openfisca/openfisca-setup-builder/commit/ccc45c7daa97c6555bf0f73f59021638de428b6f))
- build: add .editorconfig
([`ccc45c7`](https://github.com/openfisca/openfisca-setup-builder/commit/ccc45c7daa97c6555bf0f73f59021638de428b6f))

* build: add bashdep ([`da7f4da`](https://github.com/openfisca/openfisca-setup-builder/commit/da7f4da5f4fe9fd4103fac37560d00c13ee96a39))
- build: add bashdep
([`da7f4da`](https://github.com/openfisca/openfisca-setup-builder/commit/da7f4da5f4fe9fd4103fac37560d00c13ee96a39))

### Continuous Integration

* ci: use ubuntu 22.04 ([`57f5e0f`](https://github.com/openfisca/openfisca-setup-builder/commit/57f5e0fc590e99a0eaf8972f2a41fca1c2c5cd24))
- ci: use ubuntu 22.04
([`57f5e0f`](https://github.com/openfisca/openfisca-setup-builder/commit/57f5e0fc590e99a0eaf8972f2a41fca1c2c5cd24))

* ci: add poetry to ci ([`45c6725`](https://github.com/openfisca/openfisca-setup-builder/commit/45c672511153f2a5496617b9b6a8c8dcbdd580c7))
- ci: add poetry to ci
([`45c6725`](https://github.com/openfisca/openfisca-setup-builder/commit/45c672511153f2a5496617b9b6a8c8dcbdd580c7))

* ci: fix type in ref ([`adc18cd`](https://github.com/openfisca/openfisca-setup-builder/commit/adc18cd3b75e17c8b1112683ef8f8c721f7175c0))
- ci: fix type in ref
([`adc18cd`](https://github.com/openfisca/openfisca-setup-builder/commit/adc18cd3b75e17c8b1112683ef8f8c721f7175c0))

* ci: require -> needs ([`56b4a2b`](https://github.com/openfisca/openfisca-setup-builder/commit/56b4a2be81fecf4954f6482108874612453080c8))
- ci: require -> needs
([`56b4a2b`](https://github.com/openfisca/openfisca-setup-builder/commit/56b4a2be81fecf4954f6482108874612453080c8))

* ci: requires -> require ([`fb5e950`](https://github.com/openfisca/openfisca-setup-builder/commit/fb5e9500bcee6e311ebb5d7819badaa94b5102c8))
- ci: requires -> require
([`fb5e950`](https://github.com/openfisca/openfisca-setup-builder/commit/fb5e9500bcee6e311ebb5d7819badaa94b5102c8))

* ci: add workflow ([`3d8436a`](https://github.com/openfisca/openfisca-setup-builder/commit/3d8436a0365e8e6e2b9f98a9648be5e6a6bd708f))
- ci: add workflow
([`3d8436a`](https://github.com/openfisca/openfisca-setup-builder/commit/3d8436a0365e8e6e2b9f98a9648be5e6a6bd708f))

### Documentation

* docs: add README.md ([`d5d956b`](https://github.com/openfisca/openfisca-setup-builder/commit/d5d956b676955ef9647d906c69017ee124b40e45))
- docs: add README.md
([`d5d956b`](https://github.com/openfisca/openfisca-setup-builder/commit/d5d956b676955ef9647d906c69017ee124b40e45))

* docs: add CHANGELOG.md ([`9e95ecc`](https://github.com/openfisca/openfisca-setup-builder/commit/9e95ecc8d7033983c980f385c112d0e0e4013645))
- docs: add CHANGELOG.md
([`9e95ecc`](https://github.com/openfisca/openfisca-setup-builder/commit/9e95ecc8d7033983c980f385c112d0e0e4013645))

### Features

* feat: add first time setup ([`1fa2646`](https://github.com/openfisca/openfisca-setup-builder/commit/1fa26466dc8450a041f12b9b3a98d9bd81aba978))
- feat: add first time setup
([`1fa2646`](https://github.com/openfisca/openfisca-setup-builder/commit/1fa26466dc8450a041f12b9b3a98d9bd81aba978))

### Testing

* test: remove non-portable test ([`54dacca`](https://github.com/openfisca/openfisca-setup-builder/commit/54dacca2cea3db009df739a4dba7b51b11bc3e1a))
- test: remove non-portable test
([`54dacca`](https://github.com/openfisca/openfisca-setup-builder/commit/54dacca2cea3db009df739a4dba7b51b11bc3e1a))

### Unknown

* Initial commit ([`9efc6c3`](https://github.com/openfisca/openfisca-setup-builder/commit/9efc6c381bc531fe2aeacc65896fa3e2e01dc5de))
- Initial commit
([`9efc6c3`](https://github.com/openfisca/openfisca-setup-builder/commit/9efc6c381bc531fe2aeacc65896fa3e2e01dc5de))
116 changes: 116 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash
# @name build
# @deps utils/colours utils/subshell
# @brief Builds the script required for the first-time setup of a new OpenFisca.
# @usage bash build.sh

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

# @description User interruption.
# @internal
main.trap.interrupted() {
local -r exit_code=$?
trap - SIGINT
echo ''
echo -e "$(colour::warn 'Interrupted')" >&2
exit "${exit_code}"
}

# @description Cleanup on exit.
# @internal
main.trap.cleanup() {
local exit_code=$?
trap - EXIT
rm -f "./temp.sh"
echo -e "$(colour::info 'Exiting, bye!')"
exit "${exit_code}"
}

# @description Build the script.
# @arg $1 The output file path.
build::main() {
local -r out=$1
local -r root_dir=.
local -r temp_file="${root_dir}/temp.sh"
local -r source_dir="${root_dir}/src/first_time_setup"
local -r template_file="${source_dir}/main.sh"
local f
echo -e "$(colour::info "Building '${out}'")"
printf '#!/bin/bash\n' >"${temp_file}"
echo -e "$(colour::task 'Adding files...')"
# Add utils first.
for f in "${source_dir}"/**/*.sh; do
build::add_file_to_temp "${f}" "${temp_file}" "${template_file}"
done
for f in "${source_dir}"/*.sh; do
build::add_file_to_temp "${f}" "${temp_file}" "${template_file}"
done
echo -e "$(colour::done 'Files added...')"
echo -e "$(colour::task 'Applying template...')"
build::apply_template "${template_file}" "${temp_file}" "${out}"
echo -e "$(colour::done 'Template applied...')"
echo -e "$(colour::done 'Copied to dist folder...')"
mkdir -p "${root_dir}/dist"
cp -f "${out}" "${root_dir}/dist/${out}"
echo -e "$(colour::info 'Building complete :)')"
}

# @description Function to add a file's content to the temporary file.
# @arg $1 The file path.
# @arg $2 The temporary file path.
# @arg $3 The template file path.
build::add_file_to_temp() {
if [[ ${1} != "${3}" ]]; then
echo -e "$(colour::pass "Adding ${1}...")"
tail -n +7 "${1}" >>"${2}"
fi
}

# @description Function to apply the template (main) to the output file.
# @arg $1 The template file path.
# @arg $2 The temporary file path.
# @arg $3 The output file path.
build::apply_template() {
tail -n +5 "${1}" >>"${2}"
echo -e "$(colour::pass "Remove lines starting with 'source'")"
grep -v '^source' "${2}" >"${3}"
echo -e "$(colour::pass 'Make the output file executable')"
chmod u+x "${3}"
echo -e "$(colour::pass 'Formatting the output file')"
poetry run shfmt --write --simplify "${3}"
}

# Main function.
main() {
# Exit immediately if a command exits with a non-zero status.
set -o errexit
# Ensure that the ERR trap is inherited by shell functions.
set -o errtrace
# More verbosity when something within a function fails.
set -o functrace
# Treat unset variables as an error and exit immediately.
set -o nounset
# Prevent errors in a pipeline from being masked.
set -o pipefail
# Make word splitting happen only on newlines and tab characters.
IFS=$'\n\t'

# Define a cleanup functions to be called on script exit or interruption.
trap main.trap.interrupted SIGINT
trap main.trap.cleanup EXIT

# Make sure we are not being sourced. Exit if it is the case.
if "$(is::sourced)"; then
main.error 'This script should not be sourced but executed directly'
exit 1
fi

# Support being called from anywhere on the file system.
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Call the build function with the first argument.
build::main "$1"
}

main "first-time-setup.sh"
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ pyproject-fmt = "^2.4.3"
shellcheck-py = "^0.10.0.1"
shfmt-py = "^3.7.0.1"
yamllint = "^1.35.1"

[tool.semantic_release]
build_command = "./build.sh"

0 comments on commit b666d65

Please sign in to comment.