Repository navigation
129 lines (111 loc) · 4.26 KB
/
Copy pathcd-cpp.yml
File metadata and controls
129 lines (111 loc) · 4.26 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: "CD: Release"
on:
push:
tags:
- "v*"
jobs:
ci-linux:
name: "CI Linux"
uses: ./.github/workflows/ci-cpp-linux.yml
ci-macos:
name: "CI MacOS"
uses: ./.github/workflows/ci-cpp-macos.yml
ci-windows:
name: "CI Windows"
uses: ./.github/workflows/ci-cpp-windows.yml
release:
name: "Create GitHub Release"
needs: [ci-linux, ci-macos, ci-windows]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Create Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
draft: false
prerelease: false
update-xmake-repo:
name: "Update xmake-repo"
needs: release
runs-on: ubuntu-latest
steps:
- name: Check XMAKE_REPO_TOKEN availability
id: token-check
run: |
if [ -z "${{ secrets.XMAKE_REPO_TOKEN }}" ]; then
echo "::warning::Secret XMAKE_REPO_TOKEN is not configured. Skipping automatic xmake-repo update."
echo "available=false" >> "$GITHUB_OUTPUT"
else
echo "available=true" >> "$GITHUB_OUTPUT"
fi
- name: Extract version and tag
if: steps.token-check.outputs.available == 'true'
id: meta
run: |
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Download release tarball and compute SHA-256
if: steps.token-check.outputs.available == 'true'
id: checksum
run: |
TARBALL_URL="https://github.com/${{ github.repository }}/archive/refs/tags/${{ steps.meta.outputs.tag }}.tar.gz"
echo "Downloading archive from ${TARBALL_URL}..."
curl -f -sSL "${TARBALL_URL}" -o "archive.tar.gz"
SHA256=$(sha256sum "archive.tar.gz" | awk '{print $1}')
if [ -z "$SHA256" ] || [ ${#SHA256} -ne 64 ]; then
echo "::error::Failed to compute valid SHA-256 checksum for ${TARBALL_URL}"
exit 1
fi
echo "Computed SHA-256: ${SHA256}"
echo "sha256=${SHA256}" >> "$GITHUB_OUTPUT"
- name: Checkout xmake-repo
if: steps.token-check.outputs.available == 'true'
uses: actions/checkout@v4
with:
repository: "MorganCaron/xmake-repo"
token: ${{ secrets.XMAKE_REPO_TOKEN }}
path: "xmake-repo"
- name: Update package in xmake-repo
if: steps.token-check.outputs.available == 'true'
run: |
python3 - << 'EOF'
import re
pkg_file = "xmake-repo/packages/c/cpputils/xmake.lua"
tag = "${{ steps.meta.outputs.tag }}"
sha256 = "${{ steps.checksum.outputs.sha256 }}"
with open(pkg_file, "r") as file_handle:
content = file_handle.read()
version_entry = f'\tadd_versions("{tag}", "{sha256}")\n'
if re.search(rf'add_versions\(\s*"{re.escape(tag)}"', content):
print(f"Version {tag} already present. Updating checksum...")
content = re.sub(
rf'(\tadd_versions\(\s*"{re.escape(tag)}"\s*,\s*)"[^"]*"(\))',
lambda match: f'{match.group(1)}"{sha256}"{match.group(2)}',
content
)
else:
if "add_versions(" in content:
content = re.sub(r'(\tadd_versions\()', version_entry + r'\1', content, count=1)
else:
content = re.sub(r'(\ton_install\()', version_entry + r'\n\1', content, count=1)
with open(pkg_file, "w") as file_handle:
file_handle.write(content)
EOF
- name: Commit and push changes to xmake-repo
if: steps.token-check.outputs.available == 'true'
working-directory: "xmake-repo"
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add packages/c/cpputils/xmake.lua
if git diff --staged --quiet; then
echo "No changes to commit in xmake-repo."
else
git commit -m "add CppUtils ${{ steps.meta.outputs.tag }}"
git push origin master
fi