@@ -18,31 +18,59 @@ jobs:
1818 - name : Use Xcode 15.1
1919 run : sudo xcode-select -switch /Applications/Xcode_15.1.app
2020
21+ - name : Validate version input
22+ env :
23+ INPUT_VERSION : ${{ github.event.inputs.version }}
24+ run : |
25+ set -euo pipefail
26+
27+ # Validate version format: x.x.x or x.x.x-betax (e.g., 3.0.0, 3.0.0-beta1)
28+ # Uses bash regex to avoid a grep subprocess and (0|[1-9][0-9]*) to prevent leading zeros.
29+ PATTERN='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-beta[0-9]+)?$'
30+ if ! [[ "${INPUT_VERSION}" =~ $PATTERN ]]; then
31+ echo "::error::Invalid version format: ${INPUT_VERSION}"
32+ echo "::error::Version must be x.x.x or x.x.x-betax (e.g., 3.0.0 or 3.0.0-beta1)"
33+ exit 1
34+ fi
35+
36+ # Check length to prevent excessively long inputs
37+ if [ ${#INPUT_VERSION} -gt 50 ]; then
38+ echo "::error::Version string exceeds maximum length of 50 characters"
39+ exit 1
40+ fi
41+
42+ # Store validated version for use in subsequent steps
43+ echo "RELEASE_VERSION=${INPUT_VERSION}" >> "$GITHUB_ENV"
44+ echo "Version validated: ${INPUT_VERSION}"
45+
2146 - name : Check for unreleased section in changelog
2247 run : grep "## unreleased" CHANGELOG.md || (echo "::error::No unreleased section found in CHANGELOG"; exit 1)
2348
2449 - name : Set git username and email
2550 run : |
51+ set -euo pipefail
2652 git config user.name braintreeps
2753 git config user.email code@getbraintree.com
2854
2955 - name : Update version, add tag and push
3056 run : |
57+ set -euo pipefail
3158 today=$(date +'%Y-%m-%d')
32- sed -i '' 's/## unreleased.*/## '"${{ github.event.inputs.version } }"' ('"$today"')/' CHANGELOG.md
33- sed -i '' 's/\(s\.version *= *\).*/\1"'"${{ github.event.inputs.version } }"'\"/' BraintreeDropIn.podspec
34- plutil -replace CFBundleVersion -string ${{ github.event.inputs.version }} -- 'Demo/Application/Supporting Files/Braintree-Demo-Info.plist'
35- plutil -replace CFBundleShortVersionString -string ${{ github.event.inputs.version }} -- 'Demo/Application/Supporting Files/Braintree-Demo-Info.plist'
36- plutil -replace CFBundleVersion -string ${{ github.event.inputs.version }} -- 'Sources/BraintreeDropIn/Info.plist'
37- plutil -replace CFBundleShortVersionString -string ${{ github.event.inputs.version }} -- 'Sources/BraintreeDropIn/Info.plist'
59+ sed -i '' 's/## unreleased.*/## '"${RELEASE_VERSION }"' ('"$today"')/' CHANGELOG.md
60+ sed -i '' 's/\(s\.version *= *\).*/\1"'"${RELEASE_VERSION }"'\"/' BraintreeDropIn.podspec
61+ plutil -replace CFBundleVersion -string "${RELEASE_VERSION}" -- 'Demo/Application/Supporting Files/Braintree-Demo-Info.plist'
62+ plutil -replace CFBundleShortVersionString -string "${RELEASE_VERSION}" -- 'Demo/Application/Supporting Files/Braintree-Demo-Info.plist'
63+ plutil -replace CFBundleVersion -string "${RELEASE_VERSION}" -- 'Sources/BraintreeDropIn/Info.plist'
64+ plutil -replace CFBundleShortVersionString -string "${RELEASE_VERSION}" -- 'Sources/BraintreeDropIn/Info.plist'
3865
3966 git add .
40- git commit -m ' Bump version to ${{ github.event.inputs.version }}'
41- git tag ${{ github.event.inputs.version }} -a -m ' Release ${{ github.event.inputs.version }}'
42- git push origin HEAD ${{ github.event.inputs.version }}
67+ git commit -m " Bump version to ${RELEASE_VERSION}"
68+ git tag "${RELEASE_VERSION}" -a -m " Release ${RELEASE_VERSION}"
69+ git push origin HEAD "${RELEASE_VERSION}"
4370
4471 - name : Save changelog entries to a file
4572 run : |
73+ set -euo pipefail
4674 sed -e '1,/##/d' -e '/##/,$d' CHANGELOG.md > changelog_entries.md
4775
4876 - name : Create GitHub Release
@@ -51,19 +79,22 @@ jobs:
5179 env :
5280 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5381 with :
54- tag_name : ${{ github.event.inputs.version }}
55- release_name : ${{ github.event.inputs.version }}
82+ tag_name : ${{ env.RELEASE_VERSION }}
83+ release_name : ${{ env.RELEASE_VERSION }}
5684 body_path : changelog_entries.md
5785 draft : false
5886 prerelease : false
5987
6088 - name : Publish to CocoaPods
6189 env :
6290 COCOAPODS_TRUNK_TOKEN : ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
63- run : pod trunk push BraintreeDropIn.podspec
91+ run : |
92+ set -euo pipefail
93+ pod trunk push BraintreeDropIn.podspec
6494
6595 - name : Publish reference docs
6696 run : |
97+ set -euo pipefail
6798 gem install jazzy
6899 brew install sourcekitten
69100 sourcekitten doc --objc Docs/BraintreeDropIn-Umbrella-Header.h -- \
@@ -75,12 +106,12 @@ jobs:
75106 --author Braintree \
76107 --author_url http://braintreepayments.com \
77108 --github_url https://github.com/braintree/braintree-ios-drop-in \
78- --github-file-prefix https://github.com/braintree/braintree-ios-drop-in/tree/${{ github.event.inputs.version }} \
109+ --github-file-prefix " https://github.com/braintree/braintree-ios-drop-in/tree/${RELEASE_VERSION}" \
79110 --theme fullwidth \
80- --output ${{ github.event.inputs.version }}
81- cp -R Images ${{ github.event.inputs.version }} /Images
111+ --output "${RELEASE_VERSION}"
112+ cp -R Images "${RELEASE_VERSION} /Images"
82113 git checkout gh-pages
83- ln -sfn ${{ github.event.inputs.version }} current
84- git add current ${{ github.event.inputs.version }}
85- git commit -m "Publish ${{ github.event.inputs.version } } docs to github pages"
114+ ln -sfn "${RELEASE_VERSION}" current
115+ git add current "${RELEASE_VERSION}"
116+ git commit -m "Publish ${RELEASE_VERSION } docs to github pages"
86117 git push
0 commit comments