-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
104 lines (94 loc) · 3.54 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Release binary package
inputs:
framework:
description: "The XCFramework output"
required: true
script:
description: "The script generating the XCFramework"
required: true
prerelease:
description: "This is a pre-release"
default: false
gpg-key:
description: "The GPG key to commit the update"
required: true
gpg-passphrase:
description: "The passphrase of the GPG key"
version-file:
description: "The version file (contains <lib_version>-<script_version>)"
default: ".version"
runs:
using: composite
steps:
- name: Build framework
id: build
shell: bash
env:
GEN_SCRIPT: ${{ inputs.script }}
GEN_FRAMEWORK: ${{ inputs.framework }}
GEN_VERSION_FILE: ${{ inputs.version-file }}
run: |
COMPOUND_VERSION=`cat $GEN_VERSION_FILE`
LIBRARY_VERSION=${COMPOUND_VERSION%-*}
LIBRARY_MINOR=${LIBRARY_VERSION%.*}
LIBRARY_PATCH=${LIBRARY_VERSION##*.}
SCRIPT_VERSION=${COMPOUND_VERSION#*-}
if [[ "$SCRIPT_VERSION" != "$COMPOUND_VERSION" ]]; then
MERGED_PATCH=$((($LIBRARY_PATCH + 1) * 100 + $SCRIPT_VERSION))
TAG_NAME="$LIBRARY_MINOR.$MERGED_PATCH"
else
TAG_NAME="$COMPOUND_VERSION"
SCRIPT_VERSION=""
fi
./${GEN_SCRIPT} ${LIBRARY_VERSION} ${GEN_FRAMEWORK}
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
echo "library_version=$LIBRARY_VERSION" >> $GITHUB_OUTPUT
echo "script_version=$SCRIPT_VERSION" >> $GITHUB_OUTPUT
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ inputs.gpg-key }}
passphrase: ${{ inputs.gpg-passphrase }}
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
git_push_gpgsign: false
- name: Update package
id: package
shell: bash
env:
TAG_NAME: ${{ steps.build.outputs.tag }}
LIBRARY_VERSION: ${{ steps.build.outputs.library_version }}
SCRIPT_VERSION: ${{ steps.build.outputs.script_version }}
FRAMEWORK: ${{ inputs.framework }}
PACKAGE_ZIP: ${{ inputs.framework }}.zip
PACKAGE_CHECKSUM: ${{ inputs.framework }}.zip.checksum
PACKAGE_METADATA: "Package.swift"
run: |
zip -yr "$PACKAGE_ZIP" "$FRAMEWORK"
CHECKSUM=`swift package compute-checksum "$PACKAGE_ZIP"`
echo $CHECKSUM >$PACKAGE_CHECKSUM
sed -E "s/let version = \"[0-9\.]*\"/let version = \"${TAG_NAME}\"/" $PACKAGE_METADATA |
sed -E "s/let checksum = \"[0-9a-f]*\"/let checksum = \"${CHECKSUM}\"/" >$PACKAGE_METADATA.tmp
mv $PACKAGE_METADATA.tmp $PACKAGE_METADATA
RELEASE_NAME="$LIBRARY_VERSION"
if [ -n "$SCRIPT_VERSION" ] && [ "$SCRIPT_VERSION" -gt 0 ]; then
RELEASE_NAME="$RELEASE_NAME ($SCRIPT_VERSION)"
fi
git add $PACKAGE_METADATA
git commit -m "$RELEASE_NAME"
git tag "$TAG_NAME" -m "$RELEASE_NAME"
git push && git push --tags
echo "release_name=$RELEASE_NAME" >> $GITHUB_OUTPUT
echo "zip=$PACKAGE_ZIP" >> $GITHUB_OUTPUT
echo "checksum=$PACKAGE_CHECKSUM" >> $GITHUB_OUTPUT
- name: Publish release
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.package.outputs.release_name }}
tag_name: ${{ steps.build.outputs.tag }}
generate_release_notes: true
prerelease: ${{ inputs.prerelease }}
files: |
${{ steps.package.outputs.zip }}
${{ steps.package.outputs.checksum }}