mirror of
https://github.com/eth-p/bat-extras.git
synced 2024-12-04 21:40:44 +01:00
ci: Tag-to-release
This commit is contained in:
parent
d0738b7289
commit
94fbeb5b27
2
.github/actions/build/action.yaml
vendored
2
.github/actions/build/action.yaml
vendored
@ -21,7 +21,7 @@ inputs:
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
|
||||
|
||||
- name: Run build script
|
||||
shell: bash
|
||||
run: |
|
||||
|
96
.github/actions/build/create-changelog.sh
vendored
96
.github/actions/build/create-changelog.sh
vendored
@ -1,96 +0,0 @@
|
||||
#!/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
|
31
.github/actions/build/create-release-notes.sh
vendored
Normal file
31
.github/actions/build/create-release-notes.sh
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
#!/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)"
|
||||
PROJECT_DIR="$GITHUB_WORKSPACE"
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Overrides from release.sh:
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
batextras:get_git_workspace() {
|
||||
printf "%s\n" "${GITHUB_WORKSPACE}"
|
||||
}
|
||||
|
||||
batextras:get_current_commit() {
|
||||
printf "%s\n" "${GITHUB_SHA:-$(git -C "$GITHUB_WORKSPACE" rev-parse HEAD)}"
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Generate changelog:
|
||||
# -----------------------------------------------------------------------------
|
||||
set -euo pipefail
|
||||
|
||||
source "${PROJECT_DIR}/release.sh"
|
||||
batextras:generate_release_notes \
|
||||
"$(batextras:get_previous_tag_commit)" \
|
||||
"$(batextras:get_current_commit)"
|
27
.github/actions/build/create-zipball.sh
vendored
27
.github/actions/build/create-zipball.sh
vendored
@ -6,17 +6,26 @@
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$GITHUB_WORKSPACE"
|
||||
|
||||
set -euo pipefail
|
||||
source "${HERE}/version.sh"
|
||||
# -----------------------------------------------------------------------------
|
||||
# Overrides from release.sh:
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
ZIPFILE="${GITHUB_WORKSPACE}/dist/bat-extras-${CURRENT_VERSION/\.//}.zip"
|
||||
batextras:get_git_workspace() {
|
||||
printf "%s\n" "${GITHUB_WORKSPACE}"
|
||||
}
|
||||
|
||||
[[ -d "${GITHUB_WORKSPACE}/dist" ]] || mkdir -p "${GITHUB_WORKSPACE}/dist"
|
||||
[[ ! -e "${ZIPFILE}" ]] || rm "${ZIPFILE}"
|
||||
batextras:get_current_commit() {
|
||||
printf "%s\n" "${GITHUB_SHA:-$(git -C "$GITHUB_WORKSPACE" rev-parse HEAD)}"
|
||||
}
|
||||
|
||||
cd "${GITHUB_WORKSPACE}"
|
||||
zip -r "$ZIPFILE" "bin"
|
||||
zip -ru "$ZIPFILE" "doc"
|
||||
zip -ru "$ZIPFILE" "man)"
|
||||
# -----------------------------------------------------------------------------
|
||||
# Generate changelog:
|
||||
# -----------------------------------------------------------------------------
|
||||
set -euo pipefail
|
||||
source "${PROJECT_DIR}/release.sh"
|
||||
|
||||
zipball_name="bat-extras-$(batextras:get_version | sed 's/\.//')"
|
||||
zipball="${PROJECT_DIR}/${zipball_name}.zip"
|
||||
batextras:create_package "$zipball"
|
||||
|
34
.github/actions/build/version.sh
vendored
34
.github/actions/build/version.sh
vendored
@ -1,34 +0,0 @@
|
||||
#!/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
|
@ -23,7 +23,7 @@ inputs:
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
|
||||
|
||||
- name: Create directories
|
||||
shell: bash
|
||||
run: |
|
||||
@ -40,7 +40,7 @@ runs:
|
||||
--output "${RUNNER_TEMP}/bin/shfmt" \
|
||||
"https://github.com/patrickvane/shfmt/releases/download/master/shfmt_linux_amd64"
|
||||
chmod +x "${RUNNER_TEMP}/bin/shfmt"
|
||||
|
||||
|
||||
- name: Download bat (test dependency)
|
||||
uses: dsaltares/fetch-gh-release-asset@master
|
||||
if: ${{ env.ACT || inputs.test == 'true' }}
|
||||
@ -89,5 +89,4 @@ runs:
|
||||
shell: bash
|
||||
run: |
|
||||
chmod -R +x "${{ runner.temp }}/bin"
|
||||
tree "${{ runner.temp }}/bin"
|
||||
|
||||
|
42
.github/workflows/release.yaml
vendored
42
.github/workflows/release.yaml
vendored
@ -17,20 +17,42 @@ jobs:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
wait-interval: 10
|
||||
|
||||
"Changelog":
|
||||
"Release":
|
||||
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"
|
||||
- name: Install build dependencies
|
||||
uses: ./.github/actions/install-dependencies
|
||||
with:
|
||||
build: true
|
||||
test: false
|
||||
|
||||
- name: Build
|
||||
uses: ./.github/actions/build
|
||||
with:
|
||||
minify: lib
|
||||
manuals: true
|
||||
verify: false
|
||||
inline: false
|
||||
|
||||
- name: Create zipball
|
||||
run: bash "${{ github.workspace }}/.github/actions/build/create-zipball.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"
|
||||
id: changelog
|
||||
run: |
|
||||
output_file="release-notes.md"
|
||||
output_title="Release: $(date '+%Y-%m-%d')"
|
||||
|
||||
bash "${{ github.workspace }}/.github/actions/build/create-release-notes.sh" | tee "${output_file}"
|
||||
echo "::set-output name=file::${output_file}"
|
||||
echo "::set-output name=title::${output_title}"
|
||||
|
||||
- name: Create release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
artifacts: "bat-extras-*.zip"
|
||||
bodyFile: "${{steps.changelog.outputs.file}}"
|
||||
name: "${{steps.changelog.outputs.title}}"
|
||||
|
Loading…
Reference in New Issue
Block a user