Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jul 5, 2024
1 parent 56664e4 commit 787ac80
Show file tree
Hide file tree
Showing 8 changed files with 526 additions and 262 deletions.
2 changes: 1 addition & 1 deletion .github/.cspell/rust-dependencies.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

defaults:
run:
shell: bash
shell: bash --noprofile --norc -CeEuxo pipefail {0}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
Expand Down Expand Up @@ -76,6 +76,7 @@ jobs:
- almalinux:8-minimal # glibc 2.28
- almalinux:9 # glibc 2.34
- almalinux:9-minimal # glibc 2.34
- centos:6 # glibc 2.12
- centos:7 # glibc 2.17
- opensuse/leap:latest # glibc 2.31 (as of leap 15.5)
- opensuse/tumbleweed:latest # glibc 2.39 (as of 2024-04-18)
Expand All @@ -87,15 +88,14 @@ jobs:
steps:
- name: Install requirements (centos)
run: |
set -eEuxo pipefail
# https://github.com/rust-lang/rust/pull/126352
sed -i /etc/yum.repos.d/*.repo -e 's!^mirrorlist!#mirrorlist!' \
-e 's!^#baseurl=http://mirror.centos.org/!baseurl=https://vault.centos.org/!'
-e 's!^#baseurl=http://mirror.centos.org/!baseurl=https://vault.centos.org/!'
sed -i 's/enabled=1/enabled=0/' /etc/yum/pluginconf.d/fastestmirror.conf
if: startsWith(matrix.container, 'centos')
- name: Install requirements (alpine)
run: apk --no-cache add bash
shell: sh
if: startsWith(matrix.container, 'alpine')
- uses: taiki-e/checkout-action@main
- uses: taiki-e/checkout-action@dev
- run: git ls-files
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

defaults:
run:
shell: bash
shell: bash --noprofile --norc -CeEuxo pipefail {0}

jobs:
create-release:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.venv
tmp

# For platform and editor specific settings, it is recommended to add to
# a global .gitignore file.
Expand Down
19 changes: 16 additions & 3 deletions .shellcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
# https://github.com/koalaman/shellcheck/blob/HEAD/shellcheck.1.md#rc-files

# See also:
# https://www.shellcheck.net/wiki/Optional
# https://github.com/koalaman/shellcheck/wiki/Optional
# https://google.github.io/styleguide/shellguide.html

# https://www.shellcheck.net/wiki/SC2292
# https://github.com/koalaman/shellcheck/wiki/SC2244
enable=avoid-nullary-conditions

# https://github.com/koalaman/shellcheck/wiki/SC2312
# enable=check-extra-masked-returns

# https://github.com/koalaman/shellcheck/wiki/SC2310
# https://github.com/koalaman/shellcheck/wiki/SC2311
# enable=check-set-e-suppressed

# https://github.com/koalaman/shellcheck/wiki/SC2248
enable=quote-safe-variables

# https://github.com/koalaman/shellcheck/wiki/SC2292
# https://google.github.io/styleguide/shellguide.html#s6.3-tests
enable=require-double-brackets

# https://www.shellcheck.net/wiki/SC2250
# https://github.com/koalaman/shellcheck/wiki/SC2250
# https://google.github.io/styleguide/shellguide.html#s5.6-variable-expansion
enable=require-variable-braces
54 changes: 36 additions & 18 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
set -eEuo pipefail
set -CeEuo pipefail
IFS=$'\n\t'

# # shellcheck disable=SC2154
# trap 's=$?; printf >&2 "%s\n" "${0#./}:${LINENO}: \`${BASH_COMMAND}\` exit with ${s}"; exit ${s}' ERR

g() {
local cmd="$1"
shift
IFS=' '
echo "::group::${cmd} $*"
printf "::group::%s %s\n" "${cmd}" "$*"
IFS=$'\n\t'
"${cmd}" "$@"
}
Expand All @@ -22,7 +25,7 @@ retry() {
"$@"
}
warn() {
echo "::warning::$*"
printf "::warning::%s\n" "$*"
}
_sudo() {
if type -P sudo &>/dev/null; then
Expand Down Expand Up @@ -71,21 +74,33 @@ sys_install() {

wd=$(pwd)

base_distro=""
# TODO:
# - token https://github.com/taiki-e/checkout-action/issues/1
# - repository https://github.com/taiki-e/checkout-action/issues/2
# - ref/branch https://github.com/taiki-e/checkout-action/issues/3
# - sparse-checkout https://github.com/taiki-e/checkout-action/issues/4
# - tags https://github.com/actions/checkout/issues/290
# - path

base_distro=''
case "$(uname -s)" in
Linux)
host_os=linux
if grep -q '^ID_LIKE=' /etc/os-release; then
base_distro=$(grep '^ID_LIKE=' /etc/os-release | cut -d= -f2)
case "${base_distro}" in
*debian*) base_distro=debian ;;
*fedora*) base_distro=fedora ;;
*suse*) base_distro=suse ;;
*arch*) base_distro=arch ;;
*alpine*) base_distro=alpine ;;
esac
else
base_distro=$(grep '^ID=' /etc/os-release | cut -d= -f2)
if [[ -e /etc/os-release ]]; then
if grep -Eq '^ID_LIKE=' /etc/os-release; then
base_distro=$(grep -E '^ID_LIKE=' /etc/os-release | cut -d= -f2)
case "${base_distro}" in
*debian*) base_distro=debian ;;
*fedora*) base_distro=fedora ;;
*suse*) base_distro=suse ;;
*arch*) base_distro=arch ;;
*alpine*) base_distro=alpine ;;
esac
else
base_distro=$(grep -E '^ID=' /etc/os-release | cut -d= -f2)
fi
elif [[ -e /etc/redhat-release ]]; then
base_distro=fedora
fi
case "${base_distro}" in
fedora)
Expand Down Expand Up @@ -115,12 +130,12 @@ if ! type -P git &>/dev/null; then
linux*)
case "${base_distro}" in
debian | fedora | suse | arch | alpine)
echo "::group::Install packages required for checkout (git)"
printf "::group::Install packages required for checkout (git)\n"
case "${base_distro}" in
debian) sys_install ca-certificates git ;;
*) sys_install git ;;
esac
echo "::endgroup::"
printf "::endgroup::\n"
;;
*) warn "checkout-action requires git on non-Debian/Fedora/SUSE/Arch/Alpine-based Linux" ;;
esac
Expand All @@ -139,7 +154,10 @@ g git init

g git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"

g git config --local gc.auto 0
# CentOS 6's git (1.7.1) has no --local.
if git config --help | grep -Eq '\--local'; then
g git config --local gc.auto 0
fi

if [[ "${GITHUB_REF}" == "refs/heads/"* ]]; then
branch="${GITHUB_REF#refs/heads/}"
Expand Down
30 changes: 18 additions & 12 deletions tools/publish.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
set -eEuo pipefail
set -CeEuo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..
cd "$(dirname -- "$0")"/..

# shellcheck disable=SC2154
trap 's=$?; echo >&2 "$0: error on line "${LINENO}": ${BASH_COMMAND}"; exit ${s}' ERR
trap 's=$?; printf >&2 "%s\n" "${0#./}:${LINENO}: \`${BASH_COMMAND}\` exit with ${s}"; exit ${s}' ERR

# Publish a new release.
#
Expand All @@ -26,7 +26,7 @@ retry() {
"$@"
}
bail() {
echo >&2 "error: $*"
printf >&2 "error: %s\n" "$*"
exit 1
}

Expand All @@ -41,6 +41,11 @@ fi
if [[ $# -gt 1 ]]; then
bail "invalid argument '$2'"
fi
if { sed --help 2>&1 || true; } | grep -Eq '\-i extension'; then
in_place=(-i '')
else
in_place=(-i)
fi

# Make sure there is no uncommitted change.
git diff --exit-code
Expand All @@ -52,12 +57,12 @@ if gh release view "${tag}" &>/dev/null; then
fi

# Make sure that the release was created from an allowed branch.
if ! git branch | grep -q '\* main$'; then
if ! git branch | grep -Eq '\* main$'; then
bail "current branch is not 'main'"
fi

release_date=$(date -u '+%Y-%m-%d')
tags=$(git --no-pager tag | (grep -E "^${tag_prefix}[0-9]+" || true))
tags=$(git --no-pager tag | { grep -E "^${tag_prefix}[0-9]+" || true; })
if [[ -n "${tags}" ]]; then
# Make sure the same release does not exist in changelog.
if grep -Eq "^## \\[${version//./\\.}\\]" "${changelog}"; then
Expand All @@ -67,11 +72,12 @@ if [[ -n "${tags}" ]]; then
bail "link to ${version} already exist in ${changelog}"
fi
# Update changelog.
remote_url=$(grep -E '^\[Unreleased\]: https://' "${changelog}" | sed 's/^\[Unreleased\]: //; s/\.\.\.HEAD$//')
remote_url=$(grep -E '^\[Unreleased\]: https://' "${changelog}" | sed -E 's/^\[Unreleased\]: //; s/\.\.\.HEAD$//')
prev_tag="${remote_url#*/compare/}"
remote_url="${remote_url%/compare/*}"
sed -i "s/^## \\[Unreleased\\]/## [Unreleased]\\n\\n## [${version}] - ${release_date}/" "${changelog}"
sed -i "s#^\[Unreleased\]: https://.*#[Unreleased]: ${remote_url}/compare/${tag}...HEAD\\n[${version}]: ${remote_url}/compare/${prev_tag}...${tag}#" "${changelog}"
sed -E "${in_place[@]}" \
-e "s/^## \\[Unreleased\\]/## [Unreleased]\\n\\n## [${version}] - ${release_date}/" \
-e "s#^\[Unreleased\]: https://.*#[Unreleased]: ${remote_url}/compare/${tag}...HEAD\\n[${version}]: ${remote_url}/compare/${prev_tag}...${tag}#" "${changelog}"
if ! grep -Eq "^## \\[${version//./\\.}\\] - ${release_date}$" "${changelog}"; then
bail "failed to update ${changelog}"
fi
Expand All @@ -94,9 +100,9 @@ changes=$(parse-changelog "${changelog}" "${version}")
if [[ -z "${changes}" ]]; then
bail "changelog for ${version} has no body"
fi
echo "============== CHANGELOG =============="
echo "${changes}"
echo "======================================="
printf "============== CHANGELOG ==============\n"
printf "%s\n" "${changes}"
printf "=======================================\n"

if [[ -n "${tags}" ]]; then
# Create a release commit.
Expand Down
Loading

0 comments on commit 787ac80

Please sign in to comment.