mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-01-20 20:28:37 +01:00
build: Add option to print source files
This commit is contained in:
parent
7aa73f8989
commit
974073fc72
96
.github/actions/build/create-changelog.sh
vendored
Normal file
96
.github/actions/build/create-changelog.sh
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# bat-extras | Copyright (C) 2019-2023 eth-p | MIT License
|
||||
#
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
LIB="${GITHUB_WORKSPACE}/lib"
|
||||
SRC="${GITHUB_WORKSPACE}/src"
|
||||
|
||||
set -euo pipefail
|
||||
source "${HERE}/version.sh"
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Get the release date string.
|
||||
DATE_SUFFIX=""
|
||||
case "$(( $CURRENT_COMMIT_DATE_DAY ))" in
|
||||
11 | 12 | 13) DATE_SUFFIX="th" ;;
|
||||
*1) DATE_SUFFIX="st" ;;
|
||||
*2) DATE_SUFFIX="nd" ;;
|
||||
*3) DATE_SUFFIX="rd" ;;
|
||||
*) DATE_SUFFIX="th" ;;
|
||||
esac
|
||||
DATE_STR="${CURRENT_COMMIT_DATE_MONTH_HUMAN} ${CURRENT_COMMIT_DATE_DAY}${DATE_SUFFIX}, ${CURRENT_COMMIT_DATE_YEAR}"
|
||||
|
||||
# Get the script names.
|
||||
script_links=()
|
||||
script_names=()
|
||||
for script in "$SRC"/*.sh; do
|
||||
script_name="$(basename "$script" .sh)"
|
||||
script_names+=("$script_name")
|
||||
script_links+=("[\`${script_name}\`](${CURRENT_COMMIT_BLOB_URL}/doc/${script_name}.md)")
|
||||
done
|
||||
|
||||
script_pattern="$(printf 's/\\(%s\\)/`\\1`/;' "${script_names[@]}")"
|
||||
SCRIPTS="$(printf "%s, " "${script_links[@]:0:$((${#script_links[@]} - 1))}")"
|
||||
SCRIPTS="${SCRIPTS}and ${script_links[$((${#script_links[@]} - 1))]}"
|
||||
|
||||
# Generate the changelog.
|
||||
CHANGELOG_DEV=''
|
||||
CHANGELOG=''
|
||||
|
||||
ref="${CURRENT_COMMIT}"
|
||||
end="${LATEST_TAG_COMMIT}"
|
||||
echo "ref=${ref}"
|
||||
echo "end=${end}"
|
||||
while [[ "$ref" != "$end" ]]; do
|
||||
echo "see: $ref"
|
||||
is_developer=false
|
||||
ref_message="$(git -C "${GITHUB_WORKSPACE}" show -s --format=%s "$ref")"
|
||||
ref="$(git -C "${GITHUB_WORKSPACE}" rev-parse "${ref}~1")"
|
||||
|
||||
if [[ "$ref_message" =~ ^([a-z-]+):[[:space:]]*(.*)$ ]]; then
|
||||
affected_module="${BASH_REMATCH[1]}"
|
||||
|
||||
# Make module names consistent.
|
||||
case "$affected_module" in
|
||||
dev | lib | mdroff) affected_module="developer" ;;
|
||||
tests) affected_module="test" ;;
|
||||
doc) affected_module="docs" ;;
|
||||
esac
|
||||
|
||||
# Switch to the correct changelog.
|
||||
case "$affected_module" in
|
||||
test | developer | ci | build) is_developer=true ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Append to changelog.
|
||||
if "$is_developer"; then
|
||||
CHANGELOG_DEV="$CHANGELOG_DEV"$'\n'" - ${ref_message}"
|
||||
else
|
||||
CHANGELOG="$CHANGELOG"$'\n'" - ${ref_message}"
|
||||
fi
|
||||
done
|
||||
|
||||
CHANGELOG="$(sed "$script_pattern" <<< "$CHANGELOG")"
|
||||
CHANGELOG_DEV="$(sed "$script_pattern" <<< "$CHANGELOG_DEV")"
|
||||
|
||||
# Print the changelog.
|
||||
{ sed '/\\$/{N;s/\\\n//;s/\n//p;}' | tee "${GITHUB_WORKSPACE}/generated-changelog.md"; } <<- EOF
|
||||
This contains the latest versions of $SCRIPTS as of commit [$CURRENT_COMMIT]($CURRENT_COMMIT_URL) (${DATE_STR}).
|
||||
|
||||
### Changes
|
||||
$CHANGELOG
|
||||
|
||||
### Developer
|
||||
<details>
|
||||
<div markdown="1">
|
||||
|
||||
$CHANGELOG_DEV
|
||||
|
||||
</div>
|
||||
</details>
|
||||
EOF
|
22
.github/actions/build/create-zipball.sh
vendored
Normal file
22
.github/actions/build/create-zipball.sh
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# bat-extras | Copyright (C) 2019-2023 eth-p | MIT License
|
||||
#
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
set -euo pipefail
|
||||
source "${HERE}/version.sh"
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
ZIPFILE="${GITHUB_WORKSPACE}/dist/bat-extras-${CURRENT_VERSION/\.//}.zip"
|
||||
|
||||
[[ -d "${GITHUB_WORKSPACE}/dist" ]] || mkdir -p "${GITHUB_WORKSPACE}/dist"
|
||||
[[ ! -e "${ZIPFILE}" ]] || rm "${ZIPFILE}"
|
||||
|
||||
cd "${GITHUB_WORKSPACE}"
|
||||
zip -r "$ZIPFILE" "bin"
|
||||
zip -ru "$ZIPFILE" "doc"
|
||||
zip -ru "$ZIPFILE" "man)"
|
34
.github/actions/build/version.sh
vendored
Normal file
34
.github/actions/build/version.sh
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# bat-extras | Copyright (C) 2019-2023 eth-p | MIT License
|
||||
#
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
|
||||
|
||||
# Get the current commit.
|
||||
CURRENT_COMMIT="${GITHUB_SHA:-$(git -C "$GITHUB_WORKSPACE" rev-parse HEAD)}"
|
||||
CURRENT_COMMIT_BLOB_URL="${REPO_URL}/blob/${CURRENT_COMMIT}"
|
||||
CURRENT_COMMIT_URL="${REPO_URL}/commit/${CURRENT_COMMIT}"
|
||||
|
||||
CURRENT_COMMIT_DATE_YEAR="$(git -C "${GITHUB_WORKSPACE}" show -s --format="%cd" --date="format:%Y" "${CURRENT_COMMIT}")"
|
||||
CURRENT_COMMIT_DATE_MONTH="$(git -C "${GITHUB_WORKSPACE}" show -s --format="%cd" --date="format:%m" "${CURRENT_COMMIT}")"
|
||||
CURRENT_COMMIT_DATE_MONTH_HUMAN="$(git -C "${GITHUB_WORKSPACE}" show -s --format="%cd" --date="format:%B" "${CURRENT_COMMIT}")"
|
||||
CURRENT_COMMIT_DATE_DAY="$(git -C "${GITHUB_WORKSPACE}" show -s --format="%cd" --date="format:%d" "${CURRENT_COMMIT}")"
|
||||
|
||||
# Get the latest released version.
|
||||
LATEST_TAG_COMMIT="$(git -C "${GITHUB_WORKSPACE}" rev-list --tags --max-count=1)"
|
||||
LATEST_TAG_NAME="$(git -C "${GITHUB_WORKSPACE}" describe --tags --abbrev=0 "${LATEST_TAG_COMMIT}")"
|
||||
|
||||
# Get the current version.
|
||||
CURRENT_VERSION="${LATEST_TAG_NAME}-snapshot ($(git -C "${GITHUB_WORKSPACE}" rev-parse --short "${CURRENT_COMMIT}"))}"
|
||||
|
||||
# Change the version string and commit URL if a tag.
|
||||
if [[ "${GITHUB_REF_TYPE:-branch}" = "tag" ]]; then
|
||||
CURRENT_COMMIT_BLOB_URL="${REPO_URL}/blob/${GITHUB_REF_NAME}"
|
||||
if git -C "${GITHUB_WORKSPACE}" describe --tags --exact &>/dev/null; then
|
||||
CURRENT_VERSION="$(git -C "${GITHUB_WORKSPACE}" describe --tags --abbrev=0)"
|
||||
fi
|
||||
fi
|
36
.github/workflows/release.yaml
vendored
Normal file
36
.github/workflows/release.yaml
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
name: Release
|
||||
on:
|
||||
release: {}
|
||||
push:
|
||||
tags: ['*']
|
||||
|
||||
jobs:
|
||||
"Wait":
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Wait for tests to succeed
|
||||
uses: lewagon/wait-on-check-action@v1.0.0
|
||||
if: ${{ !env.ACT }}
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
running-workflow-name: 'Test'
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
wait-interval: 10
|
||||
|
||||
"Changelog":
|
||||
runs-on: ubuntu-latest
|
||||
needs: ["Wait"]
|
||||
steps:
|
||||
- name: Check out sources
|
||||
uses: actions/checkout@v3
|
||||
- name: Generate changelog
|
||||
run: bash "${{ github.workspace }}/.github/actions/build/create-changelog.sh"
|
||||
|
||||
"Package":
|
||||
runs-on: ubuntu-latest
|
||||
needs: ["Wait"]
|
||||
steps:
|
||||
- name: Check out sources
|
||||
uses: actions/checkout@v3
|
||||
- name: Generate changelog
|
||||
run: bash "${{ github.workspace }}/.github/actions/build/create-changelog.sh"
|
12
build.sh
12
build.sh
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# bat-extras | Copyright (C) 2019 eth-p | MIT License
|
||||
# bat-extras | Copyright (C) 2019-2023 eth-p | MIT License
|
||||
#
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
@ -446,12 +446,16 @@ while shiftopt; do
|
||||
--alternate-executable:git) shiftval; ALT_EXECS+=("git"); EXECUTABLE_GIT="$OPT_VAL" ;;
|
||||
--minify) shiftval; OPT_MINIFY="$OPT_VAL" ;;
|
||||
|
||||
# Print scripts.
|
||||
--show:source-paths) get_source_paths; exit 0 ;;
|
||||
|
||||
# Unknown options.
|
||||
*)
|
||||
if ! [[ -f "${SRC}/${OPT}.sh" ]]; then
|
||||
printc_err "%{RED}%s: unknown option '%s'%{CLEAR}" "$PROGRAM" "$OPT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
BUILD_FILTER+=("$OPT")
|
||||
;;
|
||||
esac
|
||||
@ -514,7 +518,7 @@ fi
|
||||
SOURCES=()
|
||||
|
||||
printc_msg "%{YELLOW}Preparing scripts...%{CLEAR}\n"
|
||||
for file in "$SRC"/*.sh; do
|
||||
while read -r file; do
|
||||
file_bin="$(basename -- "$file" ".sh")"
|
||||
buildable=false
|
||||
|
||||
@ -535,7 +539,7 @@ for file in "$SRC"/*.sh; do
|
||||
else
|
||||
printc_msg " %{YELLOW}Skipping %{MAGENTA}%s%{CLEAR}\n" "$(basename "$file_bin")"
|
||||
fi
|
||||
done
|
||||
done < <(get_source_paths)
|
||||
|
||||
if [[ "${#BUILD_FILTER[@]}" -gt 0 ]]; then
|
||||
printf "\n"
|
||||
|
Loading…
Reference in New Issue
Block a user