mirror of
https://github.com/ivuorinen/actions.git
synced 2026-01-26 03:23:59 +00:00
fix: local references, release workflow (#301)
* fix: local references, release workflow * chore: apply cr comments
This commit is contained in:
94
_tools/bump-major-version.sh
Executable file
94
_tools/bump-major-version.sh
Executable file
@@ -0,0 +1,94 @@
|
||||
#!/bin/sh
|
||||
# Bump from one major version to another (annual version bump)
|
||||
set -eu
|
||||
|
||||
OLD_VERSION="${1:-}"
|
||||
NEW_VERSION="${2:-}"
|
||||
|
||||
# Source shared utilities
|
||||
# shellcheck source=_tools/shared.sh
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
# shellcheck disable=SC1091
|
||||
. "$SCRIPT_DIR/shared.sh"
|
||||
|
||||
# Check git availability
|
||||
require_git
|
||||
|
||||
if [ -z "$OLD_VERSION" ] || [ -z "$NEW_VERSION" ]; then
|
||||
printf '%b' "${RED}Error: OLD_VERSION and NEW_VERSION arguments required${NC}\n"
|
||||
printf 'Usage: %s v2025 v2026\n' "$0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate major version format
|
||||
if ! validate_major_version "$OLD_VERSION"; then
|
||||
printf '%b' "${RED}Error: Invalid old version format: $OLD_VERSION${NC}\n"
|
||||
printf 'Expected: vYYYY (e.g., v2025)\n'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! validate_major_version "$NEW_VERSION"; then
|
||||
printf '%b' "${RED}Error: Invalid new version format: $NEW_VERSION${NC}\n"
|
||||
printf 'Expected: vYYYY (e.g., v2026)\n'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%b' "${BLUE}Bumping major version from $OLD_VERSION to $NEW_VERSION${NC}\n"
|
||||
printf '\n'
|
||||
|
||||
# Get SHA for new version tag
|
||||
if ! git rev-parse "$NEW_VERSION" >/dev/null 2>&1; then
|
||||
printf '%b' "${YELLOW}Warning: Tag $NEW_VERSION not found${NC}\n"
|
||||
printf 'Creating tag %s pointing to current HEAD...\n' "$NEW_VERSION"
|
||||
|
||||
if ! current_sha=$(git rev-parse HEAD 2>&1); then
|
||||
printf '%b' "${RED}Error: Failed to get current HEAD SHA${NC}\n" >&2
|
||||
printf 'Git command failed: git rev-parse HEAD\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git tag -a "$NEW_VERSION" -m "Major version $NEW_VERSION"
|
||||
printf '%b' "${GREEN}✓ Created tag $NEW_VERSION pointing to $current_sha${NC}\n"
|
||||
printf '\n'
|
||||
fi
|
||||
|
||||
if ! new_sha=$(git rev-list -n 1 "$NEW_VERSION" 2>&1); then
|
||||
printf '%b' "${RED}Error: Failed to get SHA for tag $NEW_VERSION${NC}\n" >&2
|
||||
printf 'Git command failed: git rev-list -n 1 "%s"\n' "$NEW_VERSION" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$new_sha" ]; then
|
||||
printf '%b' "${RED}Error: Empty SHA returned for tag $NEW_VERSION${NC}\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%b' "Target SHA for $NEW_VERSION: ${GREEN}$new_sha${NC}\n"
|
||||
printf '\n'
|
||||
|
||||
# Update all action references
|
||||
printf '%b' "${BLUE}Updating action references...${NC}\n"
|
||||
"$SCRIPT_DIR/update-action-refs.sh" "$NEW_VERSION" "tag"
|
||||
|
||||
# Commit the changes
|
||||
if ! git diff --quiet; then
|
||||
git add -- */action.yml
|
||||
git commit -m "chore: bump major version from $OLD_VERSION to $NEW_VERSION
|
||||
|
||||
This commit updates all internal action references from $OLD_VERSION
|
||||
to $NEW_VERSION.
|
||||
|
||||
🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
||||
|
||||
Co-Authored-By: Claude <noreply@anthropic.com>"
|
||||
|
||||
printf '%b' "${GREEN}✅ Committed version bump${NC}\n"
|
||||
else
|
||||
printf '%b' "${BLUE}No changes to commit${NC}\n"
|
||||
fi
|
||||
|
||||
printf '\n'
|
||||
printf '%b' "${GREEN}✅ Major version bumped successfully${NC}\n"
|
||||
printf '\n'
|
||||
printf '%b' "${YELLOW}Remember to update READMEs:${NC}\n"
|
||||
printf ' make docs\n'
|
||||
120
_tools/check-version-refs.sh
Executable file
120
_tools/check-version-refs.sh
Executable file
@@ -0,0 +1,120 @@
|
||||
#!/bin/sh
|
||||
# Check and display all current SHA-pinned action references
|
||||
set -eu
|
||||
|
||||
# Source shared utilities
|
||||
# shellcheck source=_tools/shared.sh
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
# shellcheck disable=SC1091
|
||||
. "$SCRIPT_DIR/shared.sh"
|
||||
|
||||
# Warn once if git is not available
|
||||
if ! has_git; then
|
||||
printf '%b' "${YELLOW}Warning: git is not installed or not in PATH${NC}\n" >&2
|
||||
printf 'Git tag information will not be available.\n' >&2
|
||||
fi
|
||||
|
||||
# Check for required coreutils
|
||||
for tool in find grep sed printf sort cut tr wc; do
|
||||
if ! command -v "$tool" >/dev/null 2>&1; then
|
||||
printf '%b' "${RED}Error: Required tool '%s' is not installed or not in PATH${NC}\n" "$tool" >&2
|
||||
printf 'Please install coreutils to use this script.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
printf '%b' "${BLUE}Current SHA-pinned action references:${NC}\n"
|
||||
printf '\n'
|
||||
|
||||
# Create temp files for processing
|
||||
temp_file=$(safe_mktemp)
|
||||
trap 'rm -f "$temp_file"' EXIT
|
||||
|
||||
temp_input=$(safe_mktemp)
|
||||
trap 'rm -f "$temp_file" "$temp_input"' EXIT
|
||||
|
||||
# Find all action references and collect SHA|action pairs
|
||||
# Use input redirection to avoid subshell issues with pipeline
|
||||
find . -maxdepth 2 -name "action.yml" -path "*/action.yml" ! -path "./_*" ! -path "./.github/*" -exec grep -h "uses: ivuorinen/actions/" {} \; > "$temp_input"
|
||||
|
||||
while IFS= read -r line; do
|
||||
# Extract action name and SHA using sed
|
||||
action=$(echo "$line" | sed -n 's|.*ivuorinen/actions/\([a-z-]*\)@.*|\1|p')
|
||||
sha=$(echo "$line" | sed -n 's|.*@\([a-f0-9]\{40\}\).*|\1|p')
|
||||
|
||||
if [ -n "$action" ] && [ -n "$sha" ]; then
|
||||
printf '%s\n' "$sha|$action" >> "$temp_file"
|
||||
fi
|
||||
done < "$temp_input"
|
||||
|
||||
# Check if we found any references
|
||||
if [ ! -s "$temp_file" ]; then
|
||||
printf '%b' "${YELLOW}No SHA-pinned references found${NC}\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Sort by SHA and group
|
||||
sort "$temp_file" | uniq > "${temp_file}.sorted"
|
||||
mv "${temp_file}.sorted" "$temp_file"
|
||||
|
||||
# Count unique SHAs
|
||||
sha_count=$(cut -d'|' -f1 "$temp_file" | sort -u | wc -l | tr -d ' ')
|
||||
|
||||
if [ "$sha_count" -eq 1 ]; then
|
||||
printf '%b' "${GREEN}✓ All references use the same SHA (consistent)${NC}\n"
|
||||
printf '\n'
|
||||
fi
|
||||
|
||||
# Process and display grouped by SHA
|
||||
current_sha=""
|
||||
actions_list=""
|
||||
|
||||
while IFS='|' read -r sha action; do
|
||||
if [ "$sha" != "$current_sha" ]; then
|
||||
# Print previous SHA group if exists
|
||||
if [ -n "$current_sha" ]; then
|
||||
# Try to find tags pointing to this SHA
|
||||
if has_git; then
|
||||
tags=$(git tag --points-at "$current_sha" 2>/dev/null | tr '\n' ', ' | sed 's/,$//')
|
||||
else
|
||||
tags=""
|
||||
fi
|
||||
|
||||
printf '%b' "${GREEN}SHA: $current_sha${NC}\n"
|
||||
if [ -n "$tags" ]; then
|
||||
printf '%b' " Tags: ${BLUE}$tags${NC}\n"
|
||||
fi
|
||||
printf ' Actions: %s\n' "$actions_list"
|
||||
printf '\n'
|
||||
fi
|
||||
|
||||
# Start new SHA group
|
||||
current_sha="$sha"
|
||||
actions_list="$action"
|
||||
else
|
||||
# Add to current SHA group
|
||||
actions_list="$actions_list, $action"
|
||||
fi
|
||||
done < "$temp_file"
|
||||
|
||||
# Print last SHA group
|
||||
if [ -n "$current_sha" ]; then
|
||||
if has_git; then
|
||||
tags=$(git tag --points-at "$current_sha" 2>/dev/null | tr '\n' ', ' | sed 's/,$//')
|
||||
else
|
||||
tags=""
|
||||
fi
|
||||
|
||||
printf '%b' "${GREEN}SHA: $current_sha${NC}\n"
|
||||
if [ -n "$tags" ]; then
|
||||
printf '%b' " Tags: ${BLUE}$tags${NC}\n"
|
||||
fi
|
||||
printf ' Actions: %s\n' "$actions_list"
|
||||
printf '\n'
|
||||
fi
|
||||
|
||||
printf '%b' "${BLUE}Summary:${NC}\n"
|
||||
printf ' Unique SHAs: %s\n' "$sha_count"
|
||||
if [ "$sha_count" -gt 1 ]; then
|
||||
printf '%b' " ${YELLOW}⚠ Warning: Multiple SHAs in use (consider updating)${NC}\n"
|
||||
fi
|
||||
@@ -1,15 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/sh
|
||||
# Build script for GitHub Actions Testing Docker Image
|
||||
|
||||
set -euo pipefail
|
||||
set -eu
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
IMAGE_NAME="ghcr.io/ivuorinen/actions"
|
||||
IMAGE_TAG="${1:-testing-tools}"
|
||||
FULL_IMAGE_NAME="${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
|
||||
echo "Building GitHub Actions Testing Docker Image..."
|
||||
echo "Image: $FULL_IMAGE_NAME"
|
||||
printf 'Building GitHub Actions Testing Docker Image...\n'
|
||||
printf 'Image: %s\n' "$FULL_IMAGE_NAME"
|
||||
|
||||
# Enable BuildKit for better caching and performance
|
||||
export DOCKER_BUILDKIT=1
|
||||
@@ -17,7 +17,7 @@ export DOCKER_BUILDKIT=1
|
||||
# Build the multi-stage image
|
||||
# Check for buildx support up front, then run the appropriate build command
|
||||
if docker buildx version >/dev/null 2>&1; then
|
||||
echo "Using buildx (multi-arch capable)"
|
||||
printf 'Using buildx (multi-arch capable)\n'
|
||||
docker buildx build \
|
||||
--pull \
|
||||
--tag "$FULL_IMAGE_NAME" \
|
||||
@@ -26,7 +26,7 @@ if docker buildx version >/dev/null 2>&1; then
|
||||
--load \
|
||||
"$SCRIPT_DIR"
|
||||
else
|
||||
echo "⚠️ buildx not available, using standard docker build"
|
||||
printf '⚠️ buildx not available, using standard docker build\n'
|
||||
docker build \
|
||||
--pull \
|
||||
--tag "$FULL_IMAGE_NAME" \
|
||||
@@ -35,22 +35,22 @@ else
|
||||
"$SCRIPT_DIR"
|
||||
fi
|
||||
|
||||
echo "Build completed successfully!"
|
||||
echo ""
|
||||
echo "Testing the image..."
|
||||
printf 'Build completed successfully!\n'
|
||||
printf '\n'
|
||||
printf 'Testing the image...\n'
|
||||
|
||||
# Test basic functionality
|
||||
docker run --rm "$FULL_IMAGE_NAME" whoami
|
||||
docker run --rm "$FULL_IMAGE_NAME" shellspec --version
|
||||
docker run --rm "$FULL_IMAGE_NAME" act --version
|
||||
|
||||
echo "Image tests passed!"
|
||||
echo ""
|
||||
echo "To test the image locally:"
|
||||
echo " docker run --rm -it $FULL_IMAGE_NAME"
|
||||
echo ""
|
||||
echo "To push to registry:"
|
||||
echo " docker push $FULL_IMAGE_NAME"
|
||||
echo ""
|
||||
echo "To use in GitHub Actions:"
|
||||
echo " container: $FULL_IMAGE_NAME"
|
||||
printf 'Image tests passed!\n'
|
||||
printf '\n'
|
||||
printf 'To test the image locally:\n'
|
||||
printf ' docker run --rm -it %s\n' "$FULL_IMAGE_NAME"
|
||||
printf '\n'
|
||||
printf 'To push to registry:\n'
|
||||
printf ' docker push %s\n' "$FULL_IMAGE_NAME"
|
||||
printf '\n'
|
||||
printf 'To use in GitHub Actions:\n'
|
||||
printf ' container: %s\n' "$FULL_IMAGE_NAME"
|
||||
|
||||
41
_tools/get-action-sha.sh
Executable file
41
_tools/get-action-sha.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
# Get the SHA for a specific version tag
|
||||
set -eu
|
||||
|
||||
VERSION="${1:-}"
|
||||
|
||||
# Source shared utilities
|
||||
# shellcheck source=_tools/shared.sh
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
# shellcheck disable=SC1091
|
||||
. "$SCRIPT_DIR/shared.sh"
|
||||
|
||||
# Check git availability
|
||||
require_git
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
printf '%b' "${RED}Error: VERSION argument required${NC}\n" >&2
|
||||
printf 'Usage: %s v2025\n' "$0" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if tag exists
|
||||
if ! git rev-parse "$VERSION" >/dev/null 2>&1; then
|
||||
printf '%b' "${RED}Error: Tag $VERSION not found${NC}\n" >&2
|
||||
printf '\n' >&2
|
||||
printf '%b' "${BLUE}Available tags:${NC}\n" >&2
|
||||
git tag -l 'v*' | head -20 >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get SHA for the tag
|
||||
sha=$(git rev-list -n 1 "$VERSION")
|
||||
|
||||
# Check if output is for terminal or pipe
|
||||
if [ -t 1 ]; then
|
||||
# Terminal output - show with colors
|
||||
printf '%b' "${GREEN}$sha${NC}\n"
|
||||
else
|
||||
# Piped output - just the SHA
|
||||
printf '%s\n' "$sha"
|
||||
fi
|
||||
102
_tools/release.sh
Executable file
102
_tools/release.sh
Executable file
@@ -0,0 +1,102 @@
|
||||
#!/bin/sh
|
||||
# Release script for creating versioned tags and updating action references
|
||||
set -eu
|
||||
|
||||
VERSION="${1:-}"
|
||||
|
||||
# Source shared utilities
|
||||
# shellcheck source=_tools/shared.sh
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
# shellcheck disable=SC1091
|
||||
. "$SCRIPT_DIR/shared.sh"
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
printf '%b' "${RED}Error: VERSION argument required${NC}\n"
|
||||
printf 'Usage: %s v2025.10.18\n' "$0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate version format
|
||||
if ! validate_version "$VERSION"; then
|
||||
printf '%b' "${RED}Error: Invalid version format: $VERSION${NC}\n"
|
||||
printf 'Expected: vYYYY.MM.DD (e.g., v2025.10.18)\n'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract version components
|
||||
# Remove leading 'v'
|
||||
version_no_v="${VERSION#v}"
|
||||
# Extract year, month, day
|
||||
year=$(echo "$version_no_v" | cut -d'.' -f1)
|
||||
month=$(echo "$version_no_v" | cut -d'.' -f2)
|
||||
day=$(echo "$version_no_v" | cut -d'.' -f3)
|
||||
|
||||
major="v$year"
|
||||
minor="v$year.$month"
|
||||
patch="v$year.$month.$day"
|
||||
|
||||
printf '%b' "${BLUE}Creating release $VERSION${NC}\n"
|
||||
printf ' Major: %s\n' "$major"
|
||||
printf ' Minor: %s\n' "$minor"
|
||||
printf ' Patch: %s\n' "$patch"
|
||||
printf '\n'
|
||||
|
||||
# Get current commit SHA
|
||||
current_sha=$(git rev-parse HEAD)
|
||||
printf '%b' "Current HEAD: ${GREEN}$current_sha${NC}\n"
|
||||
printf '\n'
|
||||
|
||||
# Update all action references to current SHA
|
||||
printf '%b' "${BLUE}Updating action references to $current_sha...${NC}\n"
|
||||
"$SCRIPT_DIR/update-action-refs.sh" "$current_sha" "direct"
|
||||
|
||||
# Commit the changes
|
||||
if ! git diff --quiet; then
|
||||
git add -- */action.yml
|
||||
git commit -m "chore: update action references for release $VERSION
|
||||
|
||||
This commit updates all internal action references to point to the current
|
||||
commit SHA in preparation for release $VERSION."
|
||||
|
||||
# Update SHA since we just created a new commit
|
||||
current_sha=$(git rev-parse HEAD)
|
||||
printf '%b' "${GREEN}✅ Committed updated action references${NC}\n"
|
||||
printf '%b' "New HEAD: ${GREEN}$current_sha${NC}\n"
|
||||
else
|
||||
printf '%b' "${BLUE}No changes to commit${NC}\n"
|
||||
fi
|
||||
|
||||
# Create/update tags
|
||||
printf '%b' "${BLUE}Creating tags...${NC}\n"
|
||||
|
||||
# Create patch tag
|
||||
git tag -a "$patch" -m "Release $patch"
|
||||
printf '%b' " ${GREEN}✓${NC} Created tag: $patch\n"
|
||||
|
||||
# Move/create minor tag
|
||||
if git rev-parse "$minor" >/dev/null 2>&1; then
|
||||
git tag -f -a "$minor" -m "Latest $minor release: $patch"
|
||||
printf '%b' " ${GREEN}✓${NC} Updated tag: $minor (force)\n"
|
||||
else
|
||||
git tag -a "$minor" -m "Latest $minor release: $patch"
|
||||
printf '%b' " ${GREEN}✓${NC} Created tag: $minor\n"
|
||||
fi
|
||||
|
||||
# Move/create major tag
|
||||
if git rev-parse "$major" >/dev/null 2>&1; then
|
||||
git tag -f -a "$major" -m "Latest $major release: $patch"
|
||||
printf '%b' " ${GREEN}✓${NC} Updated tag: $major (force)\n"
|
||||
else
|
||||
git tag -a "$major" -m "Latest $major release: $patch"
|
||||
printf '%b' " ${GREEN}✓${NC} Created tag: $major\n"
|
||||
fi
|
||||
|
||||
printf '\n'
|
||||
printf '%b' "${GREEN}✅ Release $VERSION created successfully${NC}\n"
|
||||
printf '\n'
|
||||
printf '%b' "${YELLOW}All tags point to: $current_sha${NC}\n"
|
||||
printf '\n'
|
||||
printf '%b' "${BLUE}Tags created:${NC}\n"
|
||||
printf ' %s\n' "$patch"
|
||||
printf ' %s\n' "$minor"
|
||||
printf ' %s\n' "$major"
|
||||
124
_tools/shared.sh
Executable file
124
_tools/shared.sh
Executable file
@@ -0,0 +1,124 @@
|
||||
#!/bin/sh
|
||||
# Shared functions and utilities for _tools/ scripts
|
||||
# This file is sourced by other scripts, not executed directly
|
||||
|
||||
# Colors (exported for use by sourcing scripts)
|
||||
# shellcheck disable=SC2034
|
||||
RED='\033[0;31m'
|
||||
# shellcheck disable=SC2034
|
||||
GREEN='\033[0;32m'
|
||||
# shellcheck disable=SC2034
|
||||
BLUE='\033[0;34m'
|
||||
# shellcheck disable=SC2034
|
||||
YELLOW='\033[1;33m'
|
||||
# shellcheck disable=SC2034
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Validate CalVer version format: vYYYY.MM.DD
|
||||
validate_version() {
|
||||
version="$1"
|
||||
|
||||
# Check format: vYYYY.MM.DD using grep
|
||||
if ! echo "$version" | grep -qE '^v[0-9]{4}\.[0-9]{1,2}\.[0-9]{1,2}$'; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Extract components
|
||||
version_no_v="${version#v}"
|
||||
year=$(echo "$version_no_v" | cut -d'.' -f1)
|
||||
month=$(echo "$version_no_v" | cut -d'.' -f2)
|
||||
day=$(echo "$version_no_v" | cut -d'.' -f3)
|
||||
|
||||
# Validate year (2020-2099)
|
||||
if [ "$year" -lt 2020 ] || [ "$year" -gt 2099 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validate month (1-12)
|
||||
if [ "$month" -lt 1 ] || [ "$month" -gt 12 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validate day (1-31)
|
||||
if [ "$day" -lt 1 ] || [ "$day" -gt 31 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Validate major version format: vYYYY
|
||||
validate_major_version() {
|
||||
version="$1"
|
||||
|
||||
# Check format: vYYYY using grep
|
||||
if ! echo "$version" | grep -qE '^v[0-9]{4}$'; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Extract year
|
||||
year="${version#v}"
|
||||
|
||||
# Validate year (2020-2099)
|
||||
if [ "$year" -lt 2020 ] || [ "$year" -gt 2099 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Validate minor version format: vYYYY.MM
|
||||
validate_minor_version() {
|
||||
version="$1"
|
||||
|
||||
# Check format: vYYYY.MM using grep
|
||||
if ! echo "$version" | grep -qE '^v[0-9]{4}\.[0-9]{1,2}$'; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Extract components
|
||||
version_no_v="${version#v}"
|
||||
year=$(echo "$version_no_v" | cut -d'.' -f1)
|
||||
month=$(echo "$version_no_v" | cut -d'.' -f2)
|
||||
|
||||
# Validate year (2020-2099)
|
||||
if [ "$year" -lt 2020 ] || [ "$year" -gt 2099 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validate month (1-12)
|
||||
if [ "$month" -lt 1 ] || [ "$month" -gt 12 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Get the directory where the calling script is located
|
||||
get_script_dir() {
|
||||
cd "$(dirname -- "$1")" && pwd
|
||||
}
|
||||
|
||||
# Check if git is available
|
||||
has_git() {
|
||||
command -v git >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Require git to be available, exit with error if not
|
||||
require_git() {
|
||||
if ! has_git; then
|
||||
printf '%b' "${RED}Error: git is not installed or not in PATH${NC}\n" >&2
|
||||
printf 'Please install git to use this script.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Create temp file with error checking
|
||||
safe_mktemp() {
|
||||
_temp_file=""
|
||||
if ! _temp_file=$(mktemp); then
|
||||
printf '%b' "${RED}Error: Failed to create temp file${NC}\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s' "$_temp_file"
|
||||
}
|
||||
71
_tools/update-action-refs.sh
Executable file
71
_tools/update-action-refs.sh
Executable file
@@ -0,0 +1,71 @@
|
||||
#!/bin/sh
|
||||
# Update all action references to a specific version tag or SHA
|
||||
set -eu
|
||||
|
||||
TARGET="${1:-}"
|
||||
MODE="${2:-tag}" # 'tag' or 'direct'
|
||||
|
||||
# Source shared utilities
|
||||
# shellcheck source=_tools/shared.sh
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
# shellcheck disable=SC1091
|
||||
. "$SCRIPT_DIR/shared.sh"
|
||||
|
||||
# Check git availability
|
||||
require_git
|
||||
|
||||
if [ -z "$TARGET" ]; then
|
||||
printf '%b' "${RED}Error: TARGET argument required${NC}\n"
|
||||
printf 'Usage: %s v2025 [mode]\n' "$0"
|
||||
printf ' mode: '\''tag'\'' (default) or '\''direct'\''\n'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get SHA based on mode
|
||||
if [ "$MODE" = "direct" ]; then
|
||||
# Direct SHA provided
|
||||
target_sha="$TARGET"
|
||||
printf '%b' "${BLUE}Using direct SHA: $target_sha${NC}\n"
|
||||
elif [ "$MODE" = "tag" ]; then
|
||||
# Resolve tag to SHA
|
||||
if ! git rev-parse "$TARGET" >/dev/null 2>&1; then
|
||||
printf '%b' "${RED}Error: Tag $TARGET not found${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
target_sha=$(git rev-list -n 1 "$TARGET")
|
||||
printf '%b' "${BLUE}Resolved $TARGET to SHA: $target_sha${NC}\n"
|
||||
else
|
||||
printf '%b' "${RED}Error: Invalid mode: $MODE${NC}\n"
|
||||
printf 'Mode must be '\''tag'\'' or '\''direct'\''\n'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate SHA format
|
||||
if ! echo "$target_sha" | grep -qE '^[a-f0-9]{40}$'; then
|
||||
printf '%b' "${RED}Error: Invalid SHA format: $target_sha${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%b' "${BLUE}Updating action references...${NC}\n"
|
||||
|
||||
# Update all action.yml files (excluding tests and .github workflows)
|
||||
# Create temp file to store results
|
||||
temp_file=$(safe_mktemp)
|
||||
trap 'rm -f "$temp_file"' EXIT
|
||||
|
||||
find . -maxdepth 2 -name "action.yml" -path "*/action.yml" ! -path "./_*" ! -path "./.github/*" | while IFS= read -r file; do
|
||||
# Use .bak extension for cross-platform sed compatibility
|
||||
if sed -i.bak "s|ivuorinen/actions/\([a-z-]*\)@[a-f0-9]\{40\}|ivuorinen/actions/\1@$target_sha|g" "$file"; then
|
||||
rm -f "${file}.bak"
|
||||
printf '%b' " ${GREEN}✓${NC} Updated: $file\n"
|
||||
echo "$file" >> "$temp_file"
|
||||
fi
|
||||
done
|
||||
|
||||
printf '\n'
|
||||
if [ -s "$temp_file" ]; then
|
||||
updated_count=$(wc -l < "$temp_file" | tr -d ' ')
|
||||
printf '%b' "${GREEN}✅ Updated $updated_count action files${NC}\n"
|
||||
else
|
||||
printf '%b' "${BLUE}No files needed updating${NC}\n"
|
||||
fi
|
||||
Reference in New Issue
Block a user