From 1a7dfc548839dea3b7935a7afa765b6750c6d310 Mon Sep 17 00:00:00 2001 From: Megabyte Labs Date: Thu, 23 Mar 2023 08:41:40 -0400 Subject: [PATCH] =?UTF-8?q?=E2=98=81=EF=B8=8F=20chore(automation):=20Apply?= =?UTF-8?q?ing=20changes=20from=20upstream=20repository.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Taskfile.yml | 140 +++++++++++++++++++++++++++++++++++++++++++++++---- package.json | 10 ++-- 2 files changed, 137 insertions(+), 13 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index aec93b182..7b446fd72 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,5 +1,6 @@ --- version: '3' + includes: ansible: taskfile: ./.config/taskfiles/ansible/Taskfile.yml @@ -184,6 +185,7 @@ includes: local: taskfile: ./../../../Taskfile-local.yml optional: true + log: optional: true taskfile: ./.config/taskfiles/log/Taskfile.yml @@ -314,6 +316,7 @@ includes: taskfile: ./.config/taskfiles/web/Taskfile-profile.yml optional: true output: interleaved + vars: DOCKERHUB_PROFILE: sh: | @@ -366,7 +369,11 @@ vars: GROUP_EXEC_ASYNC: 'false' # yamllint disable rule:line-length IGNORE_FOLDERS: >- - -path './.autodoc/*' -o -path './.cache/*' -o -path './.common*' -o -path './.config/*' -o -path './.git/*' -o -path './.modules/*' -o -path './.npm/*' -o -path './.pnpm-store/*' -o -path './.shared/*' -o -path './.task/*' -o -path './.venv/*' -o -path './.vscode/*' -o -path './build/*' -o -path './dist/*' -o -path './node_modules/*' -o -path './roles/*' -o -name pnpm-lock.yaml -o -name package-lock.json -o -name poetry.lock -o -name '.variables.json' -o -name '.git' + -path './.autodoc/*' -o -path './.cache/*' -o -path './.common*' -o -path './.config/*' -o -path './.git/*' -o + -path './.modules/*' -o -path './.npm/*' -o + -path './.pnpm-store/*' -o -path './.shared/*' -o -path './.task/*' -o -path './.venv/*' -o -path './.vscode/*' -o + -path './build/*' -o -path './dist/*' -o -path './node_modules/*' -o -path './roles/*' -o -name pnpm-lock.yaml -o + -name package-lock.json -o -name poetry.lock -o -name '.variables.json' -o -name '.git' INIT_SCRIPT: https://gitlab.com/megabyte-labs/gitlab-ci/-/raw/master/scripts/update-init.sh LOG_FIX: sh: chmod +x .config/log @@ -398,13 +405,34 @@ vars: fi PYTHON_VIRTUALENV: true REPOSITORY_SUBTYPE: - sh: if type jq &> /dev/null && [ -f package.json ]; then VER="$(jq -r .blueprint.subgroup package.json)"; if [ "$VER" == null ]; then echo "$REPOSITORY_TYPE"; else echo "$VER"; fi; else echo "$REPOSITORY_TYPE"; fi + sh: | + if [ -n "$REPOSITORY_TYPE" ]; then REPO_SUBTYPE="$REPOSITORY_TYPE"; fi + if type jq &> /dev/null && [ -f package.json ]; then + VER="$(jq -r '.blueprint.subgroup' package.json)" + if [ "$VER" == 'null' ]; then + if [ -n "$REPO_SUBTYPE" ]; then echo "$REPO_SUBTYPE"; else echo "misc"; fi + else + echo "$VER" + fi + else + if [ -n "$REPO_SUBTYPE" ]; then echo "$REPO_SUBTYPE"; else echo "misc"; fi + fi REPOSITORY_TYPE: - sh: if type jq &> /dev/null && [ -f package.json ]; then VER="$(jq -r .blueprint.group package.json)"; if [ "$VER" == null ]; then echo "$GROUP_TYPE"; else echo "$VER"; fi; else echo "$GROUP_TYPE"; fi + sh: | + if [ -n "$GROUP_TYPE" ]; then REPO_TYPE="$GROUP_TYPE"; fi + if type jq &> /dev/null && [ -f package.json ]; then + VER="$(jq -r '.blueprint.group' package.json)" + if [ "$VER" == 'null' ]; then + if [ -n "$REPO_TYPE" ]; then echo "$REPO_TYPE"; else echo "misc"; fi + else + echo "$VER" + fi + else + if [ -n "$REPO_TYPE" ]; then echo "$REPO_TYPE"; else echo "misc"; fi + fi SEMANTIC_CONFIG: semantic-release-config TIMEZONE: America/New_York - includes: - common:start: ./.config/taskfiles/common/Taskfile-start.yml + env: GOPATH: sh: | @@ -437,6 +465,7 @@ env: fi VOLTA_HOME: sh: echo "$HOME/.volta" + profile: | if [[ "$OSTYPE" == 'linux-gnu'* ]] || [[ "$OSTYPE" == 'linux-musl'* ]]; then if [ -f /home/linuxbrew/.linuxbrew/bin/brew ] && ! type brew > /dev/null; then @@ -455,6 +484,7 @@ profile: | if [ -f .venv/bin/activate ]; then . .venv/bin/activate fi + tasks: build: deps: @@ -483,6 +513,7 @@ tasks: else [[ $- == *i* ]] && task prepare || (.config/log error '{{.NONINTERACTIVE_MISSING_BUILD_CMD}}' && exit 1) fi + clean: desc: Removes optional folders that are cached during various tasks summary: | @@ -493,11 +524,13 @@ tasks: which will re-generate the project from scratch. Ideally, this task and the reset task should never be necessary. The `start` task should be used instead. vars: - CLEAN_TARGETS: .autodoc .cache .task .venv node_modules tsconfig.tsbuildinfo venv .variables.json + CLEAN_TARGETS: .autodoc .cache .task .venv node_modules tsconfig.tsbuildinfo venv + .variables.json cmds: - task: common:clean vars: CLEAN_TARGETS: '{{.CLEAN_TARGETS}}' + commit: desc: Lint staged files, report spelling errors, and open a _required_ commit dialoge summary: | @@ -514,6 +547,7 @@ tasks: to your regular `git commit -m` command to bypass the pre-commit hook. cmds: - task: common:commit + commit:all: deps: - install:software:git @@ -551,6 +585,7 @@ tasks: git add --all git commit {{end}} + commit:quick: deps: - ci:commit:config @@ -558,13 +593,39 @@ tasks: - | task --list > /dev/null || (echo "ERROR: Invalid Taskfiles!" && exit 1) git add --all - - ".config/log info 'Bypassing git hooks for git commit'\nHUSKY=0 git commit -m \"\U0001F527 chore(tweak): quick minor update\" --no-verify\n" + - | + .config/log info 'Bypassing git hooks for git commit' + HUSKY=0 git commit -m "🔧 chore(tweak): quick minor update" --no-verify - git push origin master + devcontainer: deps: - install:npm:devcontainer - install:software:docker + donothing: 'true' + + environment: + interactive: true + desc: Symlink to an environment in the `environments/` folder + summary: | + # Switch Environments Using an Interactive Dialogue + + Ansible does not really provide any great ways to switch between environments (or sets of + `host_vars/`, `group_vars/` etc.). If you place all the files and folders you wish to constitute + as an environment inside a folder named as the name of the environment in the `environments/` folder + then you can use this task to handle the symlinking and switching between environments. + + **Example of opening the interactive prompt:** + `task ansible:environment` + + **You can directly switch enironments to `environments/prod/` by running:** + `task ansible:environment -- prod` + cmds: + - task: ansible:playbook:environment + build: | + yq eval -i -P '.tasks.environment.summary = $summary' .config/taskfiles/ansible/Taskfile.yml + fix: desc: Run code auto-fixers / auto-formatters summary: | @@ -575,6 +636,7 @@ tasks: an error so the auto-fixes still have to be validated. cmds: - task: fix:all + fresh: summary: Initialize a new project with only the Taskfile.yml present cmds: @@ -586,6 +648,7 @@ tasks: - TMP="$(mktemp)" && jq -r 'del(.blueprint)' package.json > "$TMP" && mv "$TMP" package.json - bash start.sh - task: prepare + get:links: deps: - install:software:jq @@ -598,6 +661,7 @@ tasks: cmds: - .config/log info 'GitHub -----> `{{.GITHUB_URL}}`' - .config/log info 'GitLab -----> `{{.GITLAB_URL}}`' + group:exec: desc: Execute group commands on any GitLab group (including repositories in sub-groups) summary: | @@ -618,6 +682,7 @@ tasks: Be sure to wrap the command in quotes or you might observe some odd behavior. cmds: - task: git:gitlab:group:exec + init: deps: - install:software:jq @@ -650,10 +715,12 @@ tasks: - git init - task: repair - task: prepare + jumpusb: desc: Creates a JumpUSB (https://jumpusb.com) cmds: - task: install:ventoy + lint: desc: Lints the project using all linters summary: | @@ -667,6 +734,7 @@ tasks: `task lint` cmds: - task: lint:all + livereload: deps: - install:npm:nodemon @@ -706,10 +774,33 @@ tasks: .config/log error '`Taskfile-project.yml` must exist and have a `livereload` task to use with `nodemon`' && exit 1 fi - nodemon --config {{if .CLI_ARGS}}{{.CLI_ARGS}}{{else}}.config/nodemon.json{{end}} + new:project: desc: Create a new project cmds: - task: prepare + + playbook: + desc: Run the playbook + summary: | + # Run the Playbook + + This task will prompt you for the environment and inventory you would like to + run the `main.yml` playbook with. It will: + + 1. Symlink all roles in the `roles/` folder to `~/.ansible/roles` + 2. Run `task environment` (which prompts and symlinks the appropriate environment) + 3. Prompt for which inventory to use + 4. Run `ansible-playbook -i inventories/your_choice --ask-vault-pass main.yml` + + **Example usage:** + `task playbook` + + **Example bypassing prompts, using the `inventories/inventory.yml` file:** + `task playbook -- inventory.yml` + cmds: + - task: ansible:playbook:run + preload: desc: Set up your workstation in advance by installing commonly used programs summary: | @@ -752,6 +843,7 @@ tasks: - task: install:pipx:bundle - task: install:python:requirements - task: install:modules:local + prepare: desc: Prepares the project for the normal start command summary: | @@ -768,6 +860,7 @@ tasks: cmds: - task: boilerplate:check:package - task: boilerplate:clean + publish: desc: Publish a semantic release via `semantic-release` summary: | @@ -815,6 +908,7 @@ tasks: success: Successfully ran `semantic-release` via `task publish` cmds: - task: publish:semantic-release + publish:force: desc: Force a `semantic-release` even if there are no new eligible commits summary: | @@ -840,8 +934,11 @@ tasks: start: Publishing `semantic-release` update via `task publish:force` success: Successfully published update via `task publish:force` cmds: - - ".config/log info 'Bypassing git hooks for git commit'\nHUSKY=0 git commit -a --allow-empty -m '\U0001F528 chore(bump): Forced semantic-release {{.UPDATE_LEVEL}}' --no-verify\n" + - | + .config/log info 'Bypassing git hooks for git commit' + HUSKY=0 git commit -a --allow-empty -m '🔨 chore(bump): Forced semantic-release {{.UPDATE_LEVEL}}' --no-verify - task: publish + pull:upstream: desc: Pull from upstream repositories summary: | @@ -858,6 +955,7 @@ tasks: success: Successfully pulled from `upstreamRemotes` cmds: - task: common:update:upstream:remotes:pull + repair: cmds: - task: common:repair @@ -868,6 +966,7 @@ tasks: else curl -sSL {{.INIT_SCRIPT}} > "$TMP" && bash "$TMP" && rm "$TMP" fi + reset: desc: Resets the project by removing all caches and then re-generating templated files summary: | @@ -879,6 +978,7 @@ tasks: updates, it re-generates any templated files. cmds: - task: common:reset + reset:force: desc: 'Aggressively reset the project (**WARNING** This will wipe uncommitted work)' summary: | @@ -897,6 +997,7 @@ tasks: answer: cmds: - task: common:reset:force + scripts: interactive: true deps: @@ -914,6 +1015,7 @@ tasks: start: Running `NTL_RUNNER={{.NPM_PROGRAM}} ntl` cmds: - NTL_RUNNER={{.NPM_PROGRAM}} ntl + services: desc: Update elements of the repository that require API access summary: | @@ -926,6 +1028,7 @@ tasks: - task: common:update:services status: - '[ -n "$GITLAB_CI" ] && [ "$REPOSITORY_UPDATE" != "true" ]' + shell: desc: Start a terminal session using Docker with any Linux operating system compile: | @@ -959,11 +1062,13 @@ tasks: * ubuntu-21.04 cmds: - task: common:shell + ssh-keys: deps: - cloud:heroku:ssh-keys - git:github:ssh-keys - git:gitlab:ssh-keys + start: desc: Start the project by installing / updating dependencies, repairing issues, and opening a tutorial summary: | @@ -987,6 +1092,7 @@ tasks: success: Project started! cmds: - task: common:start + synchronize: desc: Set up the project and refresh it with the latest changes summary: | @@ -1007,6 +1113,7 @@ tasks: success: Successfully synchronized the project with upstream file changes and also bootstrapped the project cmds: - task: upstream:{{.PROJECT_TYPE}} + tag:deps: desc: Inject a new command in the `Taskfile.yml` that includes all tasks matching a given tag as deps summary: | @@ -1035,6 +1142,7 @@ tasks: ``` cmds: - task: common:util:task:tag:deps + template: deps: - install:npm:liquidjs @@ -1056,6 +1164,7 @@ tasks: preconditions: - sh: test -f .variables.json msg: This task requires that you have already spun up the project by running `task start` + test: deps: - install:software:jq @@ -1067,6 +1176,16 @@ tasks: This task calls `npm run test` which functions differently based on the definition made in `package.json` under the `.scripts.test` key. + ## Ansible Project Functionality + + For Ansible projects, this task wraps all the supported test methods for Ansible plays into a + convenient multi-question prompt system that supports: + + 1. Docker tests + 2. Headless VirtualBox tests + 3. VirtualBox Desktop tests which are not automatically destroyed + 4. Running the play locally + 5. Running the play over SSH on a remote target vars: NONINTERACTIVE_MISSING_TEST_CMD: There must be a `.scripts.test` definition in `package.json`! cmds: @@ -1076,6 +1195,7 @@ tasks: else [[ $- == *i* ]] && task prepare || (.config/log error '{{.NONINTERACTIVE_MISSING_TEST_CMD}}' && exit 1) fi + update: desc: Fully update the repository summary: | @@ -1102,7 +1222,9 @@ tasks: cmds: - task: common:start env: - UPDATE_PROJECT: "true" + UPDATE_PROJECT: 'true' + - task: common:update:finish + yubikey: desc: Create an OpenGPG-enabled YubiKey summary: | diff --git a/package.json b/package.json index 55ceacf24..ad468cdca 100644 --- a/package.json +++ b/package.json @@ -45,14 +45,14 @@ }, "optionalDependencies": {}, "devDependencies": { + "@commitlint/config-conventional": "latest", "eslint-config-strict-mode": "latest", "git-cz-emoji": "latest", + "handlebars-helpers": "latest", "prettier": "^2.4.1", "prettier-config-sexy-mode": "latest", "semantic-release-config": "latest", - "typescript": "^4.5.5", - "@commitlint/config-conventional": "latest", - "handlebars-helpers": "latest" + "typescript": "^4.5.5" }, "keywords": [ "ansible", @@ -129,7 +129,9 @@ "showAuthor": true }, "commitlint": { - "extends": [], + "extends": [ + "@commitlint/config-conventional" + ], "helpUrl": "https://megabyte.space/docs/contributing/commits" }, "eslintConfig": {