-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (82 loc) · 2.95 KB
/
release.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
---
name: Release
on:
push:
tags:
- "**"
permissions:
contents: write
jobs:
preflight:
runs-on: ubuntu-latest
outputs:
is_pre_release: ${{ steps.get_version_info.outputs.is_pre_release }}
module_name: ${{ steps.get_version_info.outputs.module_name }}
tag: ${{ steps.get_version_info.outputs.tag }}
version: ${{ steps.get_version_info.outputs.version }}
steps:
- id: get_version_info
name: Get version info
run: |
TAG="${GITHUB_REF#refs/*/}"
if [[ "$TAG" =~ ^[a-zA-Z0-9-]+\/[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9-]+)?$ ]]; then
MODULE_NAME=$(echo "$TAG" |cut -d/ -f 1)
VERSION=$(echo "$TAG" |cut -d/ -f 2)
else
echo "Invalid tag format: $TAG"
exit 1
fi
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
IS_PRE_RELEASE="false"
else
IS_PRE_RELEASE="true"
fi
echo "is_pre_release=${IS_PRE_RELEASE}"
echo "is_pre_release=${IS_PRE_RELEASE}" >> "$GITHUB_OUTPUT"
echo "module_name=${MODULE_NAME}"
echo "module_name=${MODULE_NAME}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
build:
uses: ./.github/workflows/build.yml
needs: preflight
release:
runs-on: ubuntu-latest
needs:
- preflight
- build
steps:
- uses: actions/checkout@v4
- name: Update version in module README
run: |
sed -i "s/\[VERSION\]/${{ needs.preflight.outputs.version }}/g" "modules/${{ needs.preflight.outputs.module_name }}/README.md"
- id: create_release_assets
name: Create release assets
run: |
ASSET_PATH="${{ runner.temp }}"
rm -rf "${ASSET_PATH}/module.tar.gz"
pushd "modules/${{ needs.preflight.outputs.module_name }}"
tar -czvf "${ASSET_PATH}/module.tar.gz" --exclude="./test" ./
cp "README.md" "${ASSET_PATH}/README.md"
popd
echo "asset_path=$ASSET_PATH" >> "$GITHUB_OUTPUT"
working-directory: ${{ github.workspace }}
- id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body_path: "${{ steps.create_release_assets.outputs.asset_path }}/README.md"
prerelease: ${{ needs.preflight.outputs.is_pre_release }}
release_name: ${{ needs.preflight.outputs.tag }}
tag_name: ${{ github.ref }}
- uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: "${{ steps.create_release_assets.outputs.asset_path }}/module.tar.gz"
asset_name: module.tar.gz
asset_content_type: application/gzip