├── .release
├── release
└── make-release-support
├── package.json
├── .pre-commit-config.yaml
├── LICENSE
├── CHANGELOG.md
├── README.md
├── CONTRIBUTING.md
├── zsh-direnv.plugin.zsh
└── Makefile
/.release/release:
--------------------------------------------------------------------------------
1 | release=0.1.3
2 | tag=0.1.3
3 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.1.3"
3 | }
4 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | - repo: https://github.com/pre-commit/pre-commit-hooks
3 | rev: v4.0.1
4 | hooks:
5 | - id: trailing-whitespace
6 | - id: end-of-file-fixer
7 | - id: check-yaml
8 | - id: check-added-large-files
9 | - id: requirements-txt-fixer
10 |
11 | - repo: https://github.com/frnmst/md-toc
12 | rev: 8.0.0
13 | hooks:
14 | - id: md-toc
15 | language_version: python3
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Patrick Tavares
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 |
4 | ## 0.1.3 (2022-07-17)
5 |
6 | ### Fixed
7 |
8 | - 🐛 fix duplicate path addition [[3cde1b5](https://github.com/ptavares/zsh-direnv/commit/3cde1b5245ec3ab2216d04896dcb37cd8514af69)]
9 |
10 |
11 |
12 | ## 0.1.2 (2022-05-23)
13 |
14 | ### Fixed
15 |
16 | - 🐛 Add alias for aarch64 machine type [[ae63b36](https://github.com/ptavares/zsh-direnv/commit/ae63b36bd1585bb81d8956d323c8e5837caa1efe)]
17 |
18 | ### Miscellaneous
19 |
20 | - fix: Add alias for aarch64 machine type [[c8be53f](https://github.com/ptavares/zsh-direnv/commit/c8be53fdd42b3f5f22cc26b315e766759940d8f2)]
21 |
22 |
23 |
24 | ## 0.1.1 (2022-03-01)
25 |
26 | ### Miscellaneous
27 |
28 | - Merge pull request [#2](https://github.com/ptavares/zsh-direnv/issues/2) from apoxa/main [[f060d00](https://github.com/ptavares/zsh-direnv/commit/f060d0043303582319d43d7e8b6ffa22ddf357ba)]
29 | - Fix darwin OSTYPE regardless of CPU arch. [[a7cbed8](https://github.com/ptavares/zsh-direnv/commit/a7cbed8bae562e47acbd9237f6b245dcc964ea9d)]
30 |
31 |
32 |
33 | ## 0.1.0 (2021-08-17)
34 |
35 | ### Added
36 |
37 | - ✨ 🎨 add precommit + lint + makefile [[8bbcead](https://github.com/ptavares/zsh-direnv/commit/8bbceadd1b8c36ebb1eb720d874a5cb188799594)]
38 | - 🎉 initial commit [[46d5ae3](https://github.com/ptavares/zsh-direnv/commit/46d5ae341ff3ede2238d299c3086020428570c5f)]
39 |
40 | ### Changed
41 |
42 | - ⚡ use releases/latest to retrieve last version [[d926430](https://github.com/ptavares/zsh-direnv/commit/d926430b2f6cb30b27fd56d187b035359f61ccd6)]
43 |
44 | ### Fixed
45 |
46 | - 🍎 add support for Linux arm64 and macOS M1 [[5761e8c](https://github.com/ptavares/zsh-direnv/commit/5761e8c24c712d49d455ab6f356ce2082873f9d0)]
47 | - 🐛 remove https checks on github with wget [[58956b2](https://github.com/ptavares/zsh-direnv/commit/58956b298cdab9f55a4dd9ba175bcaf62122d43f)]
48 |
49 | ### Miscellaneous
50 |
51 | - 📝 update ReadMe [[3f6a05a](https://github.com/ptavares/zsh-direnv/commit/3f6a05a7c5b65fb278dc9e110e75decc4ef2360a)]
52 | - 📝 update readme [[fd06308](https://github.com/ptavares/zsh-direnv/commit/fd063085d91f13200f7022cd3c6b6a0d54026629)]
53 | - Merge pull request [#1](https://github.com/ptavares/zsh-direnv/issues/1) from zakame/add-arm64 [[e3c1a4c](https://github.com/ptavares/zsh-direnv/commit/e3c1a4c92a714a8398935b26a2cede1709422056)]
54 |
55 |
56 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/pre-commit/pre-commit)
2 | 
3 |
4 | # zsh-direnv
5 |
6 | zsh plugin for installing and loading [direnv](https://github.com/direnv/direnv.git)
7 | >Inpired by [zsh-pyenv](https://github.com/mattberther/zsh-pyenv)
8 | >
9 | ## Table of content
10 |
11 | _This documentation section is generated automatically_
12 |
13 |
14 |
15 | - [zsh-direnv](#zsh-direnv)
16 | - [Table of content](#table-of-content)
17 | - [Supported Operating system](#supported-operating-system)
18 | - [Usage](#usage)
19 | - [Updating direnv](#updating-direnv)
20 | - [License](#license)
21 |
22 |
23 |
24 | ## Supported Operating system
25 |
26 | List of Operating System currently supported by the plugin:
27 |
28 | - :penguin: Linux
29 | - amd64
30 | - arm64
31 | - :apple: Darwin
32 | - amd64
33 | - arm64
34 |
35 | ## Usage
36 |
37 | Once the plugin installed, `direnv` will be available
38 |
39 | - Using [Antigen](https://github.com/zsh-users/antigen)
40 |
41 | Bundle `zsh-direnv` in your `.zshrc`
42 |
43 | ```shell
44 | antigen bundle ptavares/zsh-direnv
45 | ```
46 |
47 | - Using [zplug](https://github.com/b4b4r07/zplug)
48 |
49 | Load `zsh-direnv` as a plugin in your `.zshrc`
50 |
51 | ```shell
52 | zplug "ptavares/zsh-direnv"
53 | ```
54 |
55 | - Using [zgen](https://github.com/tarjoilija/zgen)
56 |
57 | Include the load command in your `.zshrc`
58 |
59 | ```shell
60 | zget load ptavares/zsh-direnv
61 | ```
62 |
63 | - As an [Oh My ZSH!](https://github.com/robbyrussell/oh-my-zsh) custom plugin
64 |
65 | Clone `zsh-direnv` into your custom plugins repo and load as a plugin in your `.zshrc`
66 |
67 | ```shell
68 | git clone https://github.com/ptavares/zsh-direnv.git ~/.oh-my-zsh/custom/plugins/zsh-direnv
69 | ```
70 |
71 | ```shell
72 | plugins+=(zsh-direnv)
73 | ```
74 |
75 | Keep in mind that plugins need to be added before `oh-my-zsh.sh` is sourced.
76 |
77 | - Manually
78 |
79 | Clone this repository somewhere (`~/.zsh-direnv` for example) and source it in your `.zshrc`
80 |
81 | ```shell
82 | git clone https://github.com/ptavares/zsh-direnv ~/.zsh-direnv
83 | ```
84 |
85 | ```shell
86 | source ~/.zsh-direnv/zsh-direnv.plugin.zsh
87 | ```
88 |
89 | ## Updating direnv
90 |
91 | The plugin comes with a zsh function to update [direnv](https://github.com/direnv/direnv.git) manually
92 |
93 | ```shell
94 | # From zsh shell
95 | update_zsh_direnv
96 | ```
97 |
98 | ## License
99 |
100 | [MIT](LICENCE)
101 |
--------------------------------------------------------------------------------
/.release/make-release-support:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | RELEASE=.release/release
17 |
18 | function hasChanges() {
19 | test -n "$(git status -s .)"
20 | }
21 |
22 | function getRelease() {
23 | awk -F= '/^release=/{print $2}' ${RELEASE}
24 | }
25 |
26 | function getBaseTag() {
27 | sed -n -e "s/^tag=\(.*\)$(getRelease)\$/\1/p" ${RELEASE}
28 | }
29 |
30 | function getTag() {
31 | if [ -z "$1" ] ; then
32 | awk -F= '/^tag/{print $2}' ${RELEASE}
33 | else
34 | echo "$(getBaseTag)$1"
35 | fi
36 | }
37 |
38 | function setRelease() {
39 | if [ -n "$1" ] ; then
40 | sed -i.x -e "s/^tag=.*/tag=$(getTag $1)/" ${RELEASE}
41 | sed -i.x -e "s/^release=.*/release=$1/g" ${RELEASE}
42 | rm -f ${RELEASE}.x
43 | runPreTagCommand "$1"
44 | else
45 | echo "ERROR: missing release version parameter " >&2
46 | return 1
47 | fi
48 | }
49 |
50 | function runPreTagCommand() {
51 | if [ -n "$1" ] ; then
52 | COMMAND=$(sed -n -e "s/@@RELEASE@@/$1/g" -e 's/^pre_tag_command=\(.*\)/\1/p' ${RELEASE})
53 | if [ -n "$COMMAND" ] ; then
54 | if ! OUTPUT=$(bash -c "$COMMAND" 2>&1) ; then echo $OUTPUT >&2 && exit 1 ; fi
55 | fi
56 | else
57 | echo "ERROR: missing release version parameter " >&2
58 | return 1
59 | fi
60 | }
61 |
62 | function tagExists() {
63 | tag=${1:-$(getTag)}
64 | test -n "$tag" && test -n "$(git tag | grep "^$tag\$")"
65 | }
66 |
67 | function differsFromRelease() {
68 | tag=$(getTag)
69 | ! tagExists $tag || test -n "$(git diff --shortstat -r $tag .)"
70 | }
71 |
72 | function getVersion() {
73 | result=$(getRelease)
74 |
75 | if differsFromRelease; then
76 | result="$result-$(git log -n 1 --format=%h .)"
77 | fi
78 |
79 | if hasChanges ; then
80 | result="$result-dirty"
81 | fi
82 | echo $result
83 | }
84 |
85 | function nextPatchLevel() {
86 | version=${1:-$(getRelease)}
87 | major_and_minor=$(echo $version | cut -d. -f1,2)
88 | patch=$(echo $version | cut -d. -f3)
89 | version=$(printf "%s.%d" $major_and_minor $(($patch + 1)))
90 | echo $version
91 | }
92 |
93 | function nextMinorLevel() {
94 | version=${1:-$(getRelease)}
95 | major=$(echo $version | cut -d. -f1);
96 | minor=$(echo $version | cut -d. -f2);
97 | version=$(printf "%d.%d.0" $major $(($minor + 1))) ;
98 | echo $version
99 | }
100 |
101 | function nextMajorLevel() {
102 | version=${1:-$(getRelease)}
103 | major=$(echo $version | cut -d. -f1);
104 | version=$(printf "%d.0.0" $(($major + 1)))
105 | echo $version
106 | }
107 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | :+1: :tada: First off, thanks for taking the time to contribute! :tada: :+1:
4 |
5 | The following is a set of guidelines for contributing to **zsh-direnv**. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
6 |
7 | ## Table of Content
8 |
9 |
10 |
11 | - [Contributing](#contributing)
12 | - [Table of Content](#table-of-content)
13 | - [Developers Information](#developers-information)
14 | - [Tools used](#tools-used)
15 | - [Pre-commit](#pre-commit)
16 | - [Makefile Usage](#makefile-usage)
17 | - [Styleguides](#styleguides)
18 | - [Git Commit Messages](#git-commit-messages)
19 | - [Documentation Styleguide](#documentation-styleguide)
20 |
21 |
22 |
23 | ## Tools used
24 |
25 | ### Pre-commit
26 |
27 | To facilitate testing before committing, you have the option of running automated tests with pre-commit. Each hook enables a test that we can customize.
28 |
29 | #### The main hooks configured
30 |
31 | ##### Linting
32 |
33 | ###### md-toc
34 |
35 | To ensure an automatic generation of markdown *Table of content*, the `md-toc` hook is used.
36 |
37 | #### Install dependencies
38 |
39 | * [`pre-commit`](https://pre-commit.com/#install)
40 |
41 | #### Usage Pre-commit
42 |
43 | To execution automated on commit you can install pre-commit on your repo folder
44 |
45 | ```bash
46 | pre-commit install
47 | ```
48 |
49 | To perform code test manually, you must run the pre-commit before pushing your code
50 | like this:
51 |
52 | ```bash
53 | pre-commit install
54 | pre-commit run --all
55 | ```
56 |
57 | ### Makefile
58 |
59 | #### Install dependencies
60 |
61 | * [`docker`](https://docs.docker.com/get-docker/)
62 |
63 | #### Usage
64 |
65 | :warning: **Warning** : Don't tag manually.
66 |
67 | ```bash
68 | > make help
69 |
70 | default Default Task, build program with default values
71 | version Get current version
72 | check-status Check current git status
73 | check-release Check release status
74 | major-release Do a major-release, ie : bumped first digit X+1.y.z
75 | minor-release Do a minor-release, ie : bumped second digit x.Y+1.z
76 | patch-release Do a patch-release, ie : bumped third digit x.y.Z+1
77 | precommit Execute some checks with pre-commit hooks
78 | help Show this help (Run make V=1 to enable verbose)
79 | ```
80 |
81 | ## Styleguides
82 |
83 | ### Git Commit Messages
84 |
85 | * Use the present tense ("Add feature" not "Added feature")
86 | * Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
87 | * Limit commit title to 48 characters or less
88 | * Reference issues and pull requests liberally in commit title/message
89 | * Consider starting the commit message with an applicable [emoji](https://gitmoji.dev/) like :
90 | * :sparkles: `:sparkles:` when introducing new features
91 | * :recycle: `:recycle:` when refactoring code
92 | * :art: `:art:` when improving the format/structure of the code
93 | * :zap: `:zap:` when improving performance
94 | * :memo: `:memo:` when writing docs
95 | * :bug: `:bug:` when fixing a bug
96 | * :fire: `:fire:` when removing code or files
97 | * :green_heart: `:green_heart:` when fixing the CI build
98 | * :pushpin: `:pushpin:` when pinning dependencies to specific version
99 | * :arrow_up: `:arrow_up:` when upgrading dependencies
100 | * :arrow_down: `:arrow_down:` when downgrading dependencies
101 | * :rotating_light: `:rotating_light:` when removing linter warnings
102 |
103 | ### Changelog
104 |
105 | Changelog is generated automatically (based on [gitmoji-changelog](https://github.com/frinyvonnick/gitmoji-changelog)) when building a new release.
106 |
107 |
108 | ### Documentation Styleguide
109 |
110 | * Use [Markdown](https://daringfireball.net/projects/markdown).
111 |
--------------------------------------------------------------------------------
/zsh-direnv.plugin.zsh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env zsh
2 |
3 | #####################
4 | # COMMONS
5 | #####################
6 | autoload colors is-at-least
7 |
8 | #########################
9 | # CONSTANT
10 | #########################
11 | BOLD="bold"
12 | NONE="NONE"
13 |
14 | #########################
15 | # PLUGIN MAIN
16 | #########################
17 |
18 | [[ -z "$DIRENV_HOME" ]] && export DIRENV_HOME="$HOME/.direnv"
19 |
20 | ZSH_DIRENV_VERSION_FILE=${DIRENV_HOME}/version.txt
21 |
22 | #########################
23 | # Functions
24 | #########################
25 |
26 | _zsh_direnv_log() {
27 | local font=$1
28 | local color=$2
29 | local msg=$3
30 |
31 | if [ "$font" = $BOLD ]
32 | then
33 | echo $fg_bold[$color] "[zsh-direnv-plugin] $msg" $reset_color
34 | else
35 | echo $fg[$color] "[zsh-direnv-plugin] $msg" $reset_color
36 | fi
37 | }
38 |
39 | _zsh_direnv_last_version() {
40 | echo $(curl -s https://api.github.com/repos/direnv/direnv/releases/latest | grep tag_name | cut -d '"' -f 4)
41 | }
42 |
43 | _zsh_direnv_download_install() {
44 | local version=$1
45 | local machine
46 | case "$(uname -m)" in
47 | x86_64)
48 | machine=amd64
49 | ;;
50 | arm64)
51 | machine=arm64
52 | ;;
53 | aarch64)
54 | machine=arm64
55 | ;;
56 | i686 | i386)
57 | machine=386
58 | ;;
59 | *)
60 | _zsh_direnv_log $BOLD "red" "Machine $(uname -m) not supported by this plugin"
61 | return 1
62 | ;;
63 | esac
64 | # if on Darwin, trim $OSTYPE to match the direnv release
65 | [[ "$OSTYPE" == "darwin"* ]] && local OSTYPE=darwin
66 | _zsh_direnv_log $NONE "blue" " -> download and install direnv ${version}"
67 | curl -o "${DIRENV_HOME}/direnv" -fsSL https://github.com/direnv/direnv/releases/download/${version}/direnv.${OSTYPE%-*}-${machine}
68 | chmod +x "${DIRENV_HOME}/direnv"
69 | echo ${version} > ${ZSH_DIRENV_VERSION_FILE}
70 | }
71 |
72 | _zsh_direnv_install() {
73 | _zsh_direnv_log $NONE "blue" "#############################################"
74 | _zsh_direnv_log $BOLD "blue" "Installing direnv..."
75 | _zsh_direnv_log $NONE "blue" "-> creating direnv home dir : ${DIRENV_HOME}"
76 | mkdir -p ${DIRENV_HOME} || _zsh_direnv_log $NONE "green" "dir already exist"
77 | local last_version=$(_zsh_direnv_last_version)
78 | _zsh_direnv_log $NONE "blue" "-> retrieve last version of direnv..."
79 | _zsh_direnv_download_install ${last_version}
80 | if [ $? -ne 0 ]
81 | then
82 | _zsh_direnv_log $BOLD "red" "Install KO"
83 | else
84 | _zsh_direnv_log $BOLD "green" "Install OK"
85 | fi
86 | _zsh_direnv_log $NONE "blue" "#############################################"
87 | }
88 |
89 | update_zsh_direnv() {
90 | _zsh_direnv_log $NONE "blue" "#############################################"
91 | _zsh_direnv_log $BOLD "blue" "Checking new version of direnv..."
92 |
93 | local current_version=$(cat ${ZSH_DIRENV_VERSION_FILE})
94 | local last_version=$(_zsh_direnv_last_version)
95 |
96 | if is-at-least ${last_version#v*} ${current_version#v*}
97 | then
98 | _zsh_direnv_log $BOLD "green" "Already up to date, current version : ${current_version}"
99 | else
100 | _zsh_direnv_log $NONE "blue" "-> Updating direnv..."
101 | _zsh_direnv_download_install ${last_version}
102 | _zsh_direnv_log $BOLD "green" "Update OK"
103 | fi
104 | _zsh_direnv_log $NONE "blue" "#############################################"
105 | }
106 |
107 | _zsh_direnv_load() {
108 | # export PATH if needed
109 | local -r plugin_dir=${DIRENV_HOME}
110 | # Add the plugin bin directory path if it doesn't exist in $PATH.
111 | if [[ -z ${path[(r)$plugin_dir]} ]]; then
112 | path+=($plugin_dir)
113 | fi
114 | eval "$(direnv hook zsh)"
115 | }
116 |
117 | # install direnv if it isnt already installed
118 | [[ ! -f "${ZSH_DIRENV_VERSION_FILE}" ]] && _zsh_direnv_install
119 |
120 | # load direnv if it is installed
121 | if [[ -f "${ZSH_DIRENV_VERSION_FILE}" ]]; then
122 | _zsh_direnv_load
123 | fi
124 |
125 | unset -f _zsh_direnv_install _zsh_direnv_load
126 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | ###################
2 | # RELEASE ENV
3 | ##################
4 | RELEASE_SUPPORT=.release/make-release-support
5 | RELEASE_FILE=.release/release
6 | VERSION=$(shell . $(RELEASE_SUPPORT) ; getVersion)
7 | TAG=$(shell . $(RELEASE_SUPPORT); getTag)
8 | SHA=$(shell git show-ref -s $(TAG))
9 |
10 | #####################
11 | # COMMON VALUES
12 | #####################
13 | SHELL=/bin/bash
14 | V = 0
15 | Q = $(if $(filter 1,$V),,@)
16 | M = $(shell printf "\033[34;1m▶\033[0m")
17 | MT = $(shell printf " \033[36;1m▶\033[0m")
18 | MT2 = $(shell printf " \033[36;1m-\033[0m")
19 |
20 | #####################
21 | # TARGETS
22 | #####################
23 | default: .build version ; @ ## Default Task, build program with default values
24 |
25 | version: .do-version ; @ ## Get current version
26 |
27 | check-status: .do-check-status ; @ ## Check current git status
28 |
29 | check-release: .do-check-release ; @ ## Check release status
30 |
31 | major-release: .do-major-release ; @ ## Do a major-release, ie : bumped first digit X+1.y.z
32 |
33 | minor-release: .do-minor-release ; @ ## Do a minor-release, ie : bumped second digit x.Y+1.z
34 |
35 | patch-release: .do-patch-release ; @ ## Do a patch-release, ie : bumped third digit x.y.Z+1
36 |
37 | precommit: .do-precommit ; @ ## Execute some checks with pre-commit hooks
38 |
39 | help: .do-help ; @ ## Show this help (Run make V=1 to enable verbose)
40 |
41 | # =====================
42 | # ==== BUILD =====
43 | # =====================
44 | .build: .build-info .pre-build .do-build .post-build
45 | .build-info: ; $(info $(M) Building...)
46 |
47 | .pre-build:
48 |
49 | .do-build: ; $(info $(MT) Nothing to build here.)
50 |
51 | .post-build:
52 |
53 | # =====================
54 | # ==== RELEASES =====
55 | # =====================
56 |
57 | # ===> Major
58 | .do-major-release: .major-release-info .tag-major-release .do-release version
59 | .major-release-info: ; $(info $(M) Do major release...)
60 | .tag-major-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMajorLevel)
61 | .tag-major-release: .release .tag
62 |
63 | # ===> Minor
64 | .do-minor-release: .minor-release-info .tag-minor-release .do-release version
65 | .minor-release-info: ; $(info $(M) Do minor release...)
66 | .tag-minor-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMinorLevel)
67 | .tag-minor-release: .release .tag
68 |
69 | # ===> Path
70 | .do-patch-release: .patch-release-info .tag-patch-release .do-release version
71 | .patch-release-info: ; $(info $(M) Do minor release...)
72 | .tag-patch-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextPatchLevel)
73 | .tag-patch-release: .release .tag
74 |
75 |
76 | # ===> INIT RELEASE FILE
77 | .release:
78 | @echo "release=0.0.0" > $(RELEASE_FILE)
79 | @echo "tag=0.0.0" >> $(RELEASE_FILE)
80 | @echo INFO: $(RELEASE_FILE) created
81 | @cat $(RELEASE_FILE)
82 |
83 | # ===> DO RELEASE
84 | .do-release: check-status check-release
85 |
86 | # ===> Do TAG
87 | .tag: TAG=$(shell . $(RELEASE_SUPPORT); getTag $(VERSION))
88 | .tag: check-status
89 | @. $(RELEASE_SUPPORT) ; ! tagExists $(TAG) || (echo "ERROR: tag $(TAG) for version $(VERSION) already tagged in git" >&2 && exit 1) ;
90 | @. $(RELEASE_SUPPORT) ; setRelease $(VERSION)
91 | sed -i -e "s/Release_version-.*-blue/Release_version-$(VERSION)-blue/g" README.md
92 | sed -i -e "s/\"version\": \".*\"/\"version\": \"$(VERSION)\"/g" package.json
93 | docker container run -it -v ${PWD}:/app --rm yvonnick/gitmoji-changelog:latest update $(VERSION)
94 | git add --all
95 | git commit -m ":bookmark: bumped to version $(VERSION)" ;
96 | git tag $(TAG) ;
97 | @ if [ -n "$(shell git remote -v)" ] ; then git push --tags ; else echo 'no remote to push tags to' ; fi
98 | git push
99 |
100 | # ===> CHECK RELEASE
101 | .do-check-release: ; $(info $(M) Checking release...)
102 | @. $(RELEASE_SUPPORT) ; tagExists $(TAG) || (echo "ERROR: version not yet tagged in git. make [minor,major,patch]-release." >&2 && exit 1) ;
103 | @. $(RELEASE_SUPPORT) ; ! differsFromRelease $(TAG) || (echo "ERROR: current directory differs from tagged $(TAG). make [minor,major,patch]-release." ; exit 1)
104 |
105 |
106 | # =======================
107 | # === COMMONS =====
108 | # =======================
109 |
110 | # ===> Get current version
111 | .do-version: ; $(info $(M) Current version)
112 | $(info $(MT) $(VERSION))
113 |
114 | # ===> Check current repository status
115 | .do-check-status: ; $(info $(M) Checking git status...)
116 | @. $(RELEASE_SUPPORT) ; ! hasChanges || (echo "ERROR: there are still outstanding changes" >&2 && exit 1) ;
117 |
118 | # ===> Run pre-commit
119 | .do-precommit: ; $(info $(M) Checking pre-commit hooks...)
120 | pre-commit run -a
121 |
122 | # ===> Help
123 | .do-help:
124 | @grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
125 | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
126 |
127 | # ===========================================================================================
128 |
129 | BUILD_TARGETS := pre-build do-build post-build build
130 | REALEASE_TARGETS := check-release major-release minor-release patch-release
131 | INFO_TARGETS := version .do-version check-status .do-check-status
132 | PRECOMMIT_TARGETS := precommit do-precommit
133 | HELP_TARGETS := help .do-help
134 |
135 | .PHONY: $(BUILD_TARGETS) $(RELEASE_TARGETS) $(INFO_TARGETS) $(PRECOMMIT_TARGETS) $(HELP_TARGETS)
--------------------------------------------------------------------------------