Reuse version normalizer (#44)

* Reuse get_openssl_version() from external script

* Improve variables usage in workflow

* Fix release notes generation

* Rename main job
This commit is contained in:
Davide De Rosa 2021-12-01 12:43:11 +01:00 committed by GitHub
parent 2f25fce94b
commit ac0d6f6d42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 37 deletions

View File

@ -8,7 +8,7 @@ on:
- '.version' - '.version'
jobs: jobs:
build_openssl: publish_binary_release:
runs-on: macos-11 runs-on: macos-11
env: env:
OPENSSL_TARGETS: "ios-sim-cross-x86_64 ios-sim-cross-arm64 ios64-cross-arm64 ios64-cross-arm64e macos64-x86_64 macos64-arm64 mac-catalyst-x86_64 mac-catalyst-arm64" OPENSSL_TARGETS: "ios-sim-cross-x86_64 ios-sim-cross-arm64 ios64-cross-arm64 ios64-cross-arm64e macos64-x86_64 macos64-arm64 mac-catalyst-x86_64 mac-catalyst-arm64"
@ -18,18 +18,13 @@ jobs:
id: lib id: lib
timeout-minutes: 60 timeout-minutes: 60
run: | run: |
TAG_NAME=`cat .version` source scripts/get-openssl-version.sh
SCRIPT_NUM="${TAG_NAME#1.1.}" # 11200 COMPOUND_VERSION=`cat .version`
PATCH_COMPOUND=$((SCRIPT_NUM / 100)) # 112 OPENSSL_VERSION=${COMPOUND_VERSION%-*}
PATCH=$((PATCH_COMPOUND / 100)) # 1 SCRIPT_VERSION=${COMPOUND_VERSION#*-}
SUBPATCH_NUM=$((PATCH_COMPOUND - PATCH * 100)) # 12 TAG_NAME=$(get_openssl_version $OPENSSL_VERSION $SCRIPT_VERSION)
SUBPATCH_ASCII=$((SUBPATCH_NUM + 96)) # 108
SUBPATCH_HEX=`printf '%x' $SUBPATCH_ASCII` # 6c
SUBPATCH=`printf "\\x$SUBPATCH_HEX"` # 'l'
OPENSSL_VERSION="1.1.$PATCH$SUBPATCH"
SCRIPT_VERSION=$((SCRIPT_NUM - PATCH_COMPOUND * 100))
echo "Compiling OpenSSL $OPENSSL_VERSION" echo "Compiling OpenSSL $OPENSSL_VERSION"
./build-libssl.sh --version="$OPENSSL_VERSION" --targets="$OPENSSL_TARGETS" --disable-bitcode ./build-libssl.sh --version="$OPENSSL_VERSION" --targets="$OPENSSL_TARGETS" --disable-bitcode
@ -58,41 +53,44 @@ jobs:
- name: Update Package.swift - name: Update Package.swift
id: package id: package
env: env:
PACKAGE_FILE: "Package.swift" TAG_NAME: ${{ steps.lib.outputs.tag }}
OPENSSL_VERSION: ${{ steps.lib.outputs.openssl_version }}
SCRIPT_VERSION: ${{ steps.lib.outputs.script_version }}
PACKAGE_METADATA: "Package.swift"
PACKAGE_ARTIFACT: ${{ steps.framework.outputs.artifact }}
PACKAGE_CHECKSUM: ${{ steps.framework.outputs.artifact }}.checksum
run: | run: |
TAG="${{ steps.lib.outputs.tag }}" CHECKSUM=`swift package compute-checksum "$PACKAGE_ARTIFACT"`
CHECKSUM=`swift package compute-checksum ${{ steps.framework.outputs.artifact }}` echo $CHECKSUM >$PACKAGE_CHECKSUM
echo $CHECKSUM >${{ steps.framework.outputs.artifact }}.checksum
sed -E "s@/[0-9\.]+/(openssl.xcframework.zip)@/$TAG/\\1@" $PACKAGE_FILE | sed -E "s@/[0-9\.]+/(openssl.xcframework.zip)@/$TAG_NAME/\\1@" $PACKAGE_METADATA |
sed -E "s/checksum: \"[0-9a-f]+\"/checksum: \"$CHECKSUM\"/" >$PACKAGE_FILE.tmp sed -E "s/checksum: \"[0-9a-f]+\"/checksum: \"$CHECKSUM\"/" >$PACKAGE_METADATA.tmp
mv $PACKAGE_FILE.tmp $PACKAGE_FILE mv $PACKAGE_METADATA.tmp $PACKAGE_METADATA
OPENSSL_VERSION=${{ steps.lib.outputs.openssl_version }}
SCRIPT_VERSION=${{ steps.lib.outputs.script_version }}
RELEASE_NAME="OpenSSL $OPENSSL_VERSION" RELEASE_NAME="OpenSSL $OPENSSL_VERSION"
if [ $SCRIPT_VERSION -gt 0 ]; then if [ $SCRIPT_VERSION -gt 0 ]; then
RELEASE_NAME="$RELEASE_NAME ($SCRIPT_VERSION)" RELEASE_NAME="$RELEASE_NAME ($SCRIPT_VERSION)"
fi fi
git add $PACKAGE_FILE git add $PACKAGE_METADATA
git commit -m "$RELEASE_NAME" git commit -m "$RELEASE_NAME"
git tag ${{ steps.lib.outputs.tag }} -m "$RELEASE_NAME" git tag "$TAG_NAME" -m "$RELEASE_NAME"
git push && git push --tags git push && git push --tags
BODY_PATH="release-notes.txt" RELEASE_NOTES="release-notes.txt"
echo "Compiled for iOS and macOS (plus Catalyst)." >>$BODY_PATH echo "Compiled for iOS and macOS (plus Catalyst)." >$RELEASE_NOTES
echo >>$BODY_PATH echo >>$RELEASE_NOTES
echo "SwiftPM checksum: $CHECKSUM" >$BODY_PATH echo "SwiftPM checksum: $CHECKSUM" >>$RELEASE_NOTES
echo "::set-output name=release_name::$RELEASE_NAME" echo "::set-output name=release_name::$RELEASE_NAME"
echo "::set-output name=checksum::$CHECKSUM" echo "::set-output name=release_notes::$RELEASE_NOTES"
echo "::set-output name=checksum::$PACKAGE_CHECKSUM"
- name: Publish release - name: Publish release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
name: ${{ steps.package.outputs.release_name }} name: ${{ steps.package.outputs.release_name }}
body_path: ${{ steps.package.outputs.release_notes }}
tag_name: ${{ steps.lib.outputs.tag }} tag_name: ${{ steps.lib.outputs.tag }}
body_path: release-notes.txt
files: | files: |
${{ steps.framework.outputs.artifact }} ${{ steps.framework.outputs.artifact }}
${{ steps.framework.outputs.artifact }}.checksum ${{ steps.package.outputs.checksum }}

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
source scripts/get-openssl-version.sh
set -euo pipefail set -euo pipefail
@ -111,14 +112,10 @@ function get_min_sdk() {
# 'g' = 103 -> 6 + 1 = 07 (zero-padded) # 'g' = 103 -> 6 + 1 = 07 (zero-padded)
# 1.1.107 # 1.1.107
# #
function get_openssl_version() { function get_openssl_version_from_file() {
local opensslv=$1 local opensslv=$1
local std_version=$(awk '/define OPENSSL_VERSION_TEXT/ && !/-fips/ {print $5}' "$opensslv") local std_version=$(awk '/define OPENSSL_VERSION_TEXT/ && !/-fips/ {print $5}' "$opensslv")
local generic_version=${std_version%?} echo $(get_openssl_version $std_version)
local subpatch=${std_version: -1}
local subpatch_number=$(($(printf '%d' \'$subpatch) - 97 + 1))
local normalized_version="${generic_version}$(printf '%02d' $subpatch_number)"
echo $normalized_version
} }
if [ $FWTYPE == "dynamic" ]; then if [ $FWTYPE == "dynamic" ]; then
@ -210,7 +207,7 @@ if [ $FWTYPE == "dynamic" ]; then
cp -r include/$FWNAME/* $FWDIR/Headers/ cp -r include/$FWNAME/* $FWDIR/Headers/
cp -L assets/$SYS/Info.plist $FWDIR/Info.plist cp -L assets/$SYS/Info.plist $FWDIR/Info.plist
MIN_SDK_VERSION=$(get_min_sdk "$FWDIR/$FWNAME") MIN_SDK_VERSION=$(get_min_sdk "$FWDIR/$FWNAME")
OPENSSL_VERSION=$(get_openssl_version "$FWDIR/Headers/opensslv.h") OPENSSL_VERSION=$(get_openssl_version_from_file "$FWDIR/Headers/opensslv.h")
sed -e "s/\\\$(MIN_SDK_VERSION)/$MIN_SDK_VERSION/g" \ sed -e "s/\\\$(MIN_SDK_VERSION)/$MIN_SDK_VERSION/g" \
-e "s/\\\$(OPENSSL_VERSION)/$OPENSSL_VERSION/g" \ -e "s/\\\$(OPENSSL_VERSION)/$OPENSSL_VERSION/g" \
-i '' "$FWDIR/Info.plist" -i '' "$FWDIR/Info.plist"
@ -240,7 +237,7 @@ else
cp -r include/$FWNAME/* $FWDIR/Headers/ cp -r include/$FWNAME/* $FWDIR/Headers/
cp -L assets/$SYS/Info.plist $FWDIR/Info.plist cp -L assets/$SYS/Info.plist $FWDIR/Info.plist
MIN_SDK_VERSION=$(get_min_sdk "$FWDIR/$FWNAME") MIN_SDK_VERSION=$(get_min_sdk "$FWDIR/$FWNAME")
OPENSSL_VERSION=$(get_openssl_version "$FWDIR/Headers/opensslv.h") OPENSSL_VERSION=$(get_openssl_version_from_file "$FWDIR/Headers/opensslv.h")
sed -e "s/\\\$(MIN_SDK_VERSION)/$MIN_SDK_VERSION/g" \ sed -e "s/\\\$(MIN_SDK_VERSION)/$MIN_SDK_VERSION/g" \
-e "s/\\\$(OPENSSL_VERSION)/$OPENSSL_VERSION/g" \ -e "s/\\\$(OPENSSL_VERSION)/$OPENSSL_VERSION/g" \
-i '' "$FWDIR/Info.plist" -i '' "$FWDIR/Info.plist"

12
scripts/get-openssl-version.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
function get_openssl_version() {
local std_version=$1
local script_version=${2:-}
local generic_version=${std_version%?}
local subpatch=${std_version: -1}
local subpatch_number=$(($(printf '%d' \'$subpatch) - 97 + 1))
subpatch_number="$(printf '%02d' $subpatch_number)"
script_version="$(printf '%02d' $script_version)"
local normalized_version="${generic_version}${subpatch_number}${script_version}"
echo $normalized_version
}