Skip to content

Commit 43e999e

Browse files
committed
ci: add guards to bash script
1 parent 1515354 commit 43e999e

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

.github/workflows/package-release.yml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,32 @@ jobs:
3838
- name: Create package
3939
id: create_package
4040
run: |
41-
# Capture output in a variable
42-
RESULT=$(.github/workflows/scripts/create-package.sh "${{ steps.version.outputs.version }}" "${{ steps.current_time.outputs.timestamp }}")
43-
# Check if script succeeded
44-
if [ $? -ne 0 ]; then
45-
echo "Error creating package"
41+
# Create the package and capture only the filename
42+
FILENAME=$(.github/workflows/scripts/create-package.sh "${{ steps.version.outputs.version }}" "${{ steps.current_time.outputs.timestamp }}")
43+
44+
# Debug output
45+
echo "Package script returned: '$FILENAME'"
46+
47+
# Validate that the file exists
48+
if [ -f "$FILENAME" ]; then
49+
echo "Found package file: $FILENAME"
50+
echo "package_path=$FILENAME" >> $GITHUB_OUTPUT
51+
else
52+
echo "ERROR: Package file not found: $FILENAME"
4653
exit 1
4754
fi
48-
# Check if file exists
49-
if [ ! -f "$RESULT" ]; then
50-
echo "Package file not found: $RESULT"
51-
exit 1
52-
fi
53-
# Set outputs
54-
echo "PACKAGE_PATH=$RESULT" >> $GITHUB_ENV
55-
echo "package_path=$RESULT" >> $GITHUB_OUTPUT
55+
56+
- name: Debug outputs
57+
run: |
58+
echo "Version: ${{ steps.version.outputs.version }}"
59+
echo "Package path: ${{ steps.create_package.outputs.package_path }}"
60+
ls -la
5661
5762
- name: Create Release
5863
id: create_release
5964
uses: softprops/action-gh-release@v1
60-
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
65+
# Run this step in all cases where we have a package
66+
if: steps.create_package.outputs.package_path != ''
6167
with:
6268
files: ${{ steps.create_package.outputs.package_path }}
6369
name: Rider-Waite-Smith Tarot Deck v${{ steps.version.outputs.version }}

.github/workflows/scripts/create-package.sh

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
# Get the version from the first parameter
45
VERSION=$1
@@ -14,6 +15,8 @@ fi
1415
PACKAGE_NAME="rider-waite-smith-${VERSION}"
1516
ZIP_FILE="${PACKAGE_NAME}.zip"
1617

18+
echo "Creating package: ${ZIP_FILE}..."
19+
1720
# Create a temporary directory for packaging
1821
TEMP_DIR=$(mktemp -d)
1922
DECK_DIR="${TEMP_DIR}/${PACKAGE_NAME}"
@@ -33,22 +36,14 @@ Repository: ${GITHUB_REPOSITORY:-"arcanaland/specifications"}
3336
This package follows the Tarot Deck Specification v1.0.
3437
EOL
3538

36-
# Create the zip file and suppress the output
37-
(cd "${TEMP_DIR}" && zip -r "${ZIP_FILE}" "${PACKAGE_NAME}" >/dev/null)
38-
39-
# Check if zip command was successful
40-
if [ $? -ne 0 ]; then
41-
echo "ERROR: Failed to create zip file" >&2
42-
rm -rf "${TEMP_DIR}"
43-
exit 1
44-
fi
39+
# Create the zip file and redirect output to stderr so it doesn't affect the function output
40+
(cd "${TEMP_DIR}" && zip -r "${ZIP_FILE}" "${PACKAGE_NAME}" 1>&2)
4541

4642
# Move the zip file to the current directory
4743
mv "${TEMP_DIR}/${ZIP_FILE}" .
4844

4945
# Clean up the temporary directory
5046
rm -rf "${TEMP_DIR}"
5147

52-
# Output just the filename, no other text
53-
echo "${ZIP_FILE}"
54-
48+
echo "Package created: ${ZIP_FILE}" >&2
49+
printf "%s" "${ZIP_FILE}" # Print the filename without newline

0 commit comments

Comments
 (0)