Skip to content

Commit aa8dbb6

Browse files
authored
Create sync workflow for release management
1 parent 741f583 commit aa8dbb6

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

.github/workflows/sync.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Sync release
2+
on:
3+
workflow_dispatch:
4+
repository_dispatch:
5+
types: [sync-release]
6+
7+
permissions:
8+
id-token: write
9+
contents: write
10+
actions: write
11+
attestations: write
12+
13+
env:
14+
GH_TOKEN: ${{ github.token }}
15+
SOURCE_REPO: 'AlirezaParsi/COPG'
16+
MODULE_NAME: 'COPG'
17+
18+
jobs:
19+
get_missing_tags:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
tags: ${{ steps.check.outputs.tags }}
23+
latest: ${{ steps.check.outputs.latest }}
24+
steps:
25+
- name: Check tags
26+
id: check
27+
run: |
28+
SOURCE_TAGS=$(gh api repos/$SOURCE_REPO/tags | jq -r '.[].name' | sort)
29+
CURRENT_TAGS=$(gh api repos/$GITHUB_REPOSITORY/tags | jq -r '.[].name' | sort)
30+
MISSING=$(comm -23 <(echo "$SOURCE_TAGS") <(echo "$CURRENT_TAGS"))
31+
MISSING_JSON=$(echo "$MISSING" | jq -R -s -c 'split("\n")[:-1] | map(select(. != ""))')
32+
echo "tags=$MISSING_JSON" >> $GITHUB_OUTPUT
33+
LATEST=$(echo "$SOURCE_TAGS" | tail -1)
34+
echo "latest=$LATEST" >> $GITHUB_OUTPUT
35+
36+
sync_and_release:
37+
needs: get_missing_tags
38+
if: needs.get_missing_tags.outputs.tags != '[]'
39+
runs-on: ubuntu-latest
40+
strategy:
41+
matrix:
42+
tag: ${{ fromJson(needs.get_missing_tags.outputs.tags) }}
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
with:
47+
token: ${{ secrets.REPO_SYNC_PAT }}
48+
49+
- name: Pull release artifact and fix line endings
50+
run: |
51+
gh release download ${{ matrix.tag }} --repo $SOURCE_REPO --pattern "$MODULE_NAME*.zip" --dir ./dl
52+
ZIP_FILE=$(ls ./dl/$MODULE_NAME*.zip | head -1)
53+
54+
python3 - "$ZIP_FILE" "$MODULE_NAME.zip" <<'PYEOF'
55+
import sys, zipfile
56+
src, dst = sys.argv[1], sys.argv[2]
57+
with zipfile.ZipFile(src, 'r') as zin, \
58+
zipfile.ZipFile(dst, 'w', zipfile.ZIP_DEFLATED) as zout:
59+
for item in zin.infolist():
60+
data = zin.read(item.filename)
61+
if item.filename == 'module.prop':
62+
data = data.replace(b'\r\n', b'\n').replace(b'\r', b'\n')
63+
zout.writestr(item, data)
64+
PYEOF
65+
66+
BODY=$(gh release view ${{ matrix.tag }} --repo $SOURCE_REPO --json body -q .body)
67+
echo "RELEASE_BODY<<EOF" >> $GITHUB_ENV
68+
echo "$BODY" >> $GITHUB_ENV
69+
echo "EOF" >> $GITHUB_ENV
70+
71+
- name: Create Release
72+
uses: KernelSU-Modules-Repo/module_release@main
73+
with:
74+
tag_name: ${{ matrix.tag }}
75+
make_latest: ${{ matrix.tag == needs.get_missing_tags.outputs.latest }}
76+
file: "${{ env.MODULE_NAME }}.zip"
77+
body: ${{ env.RELEASE_BODY }}
78+
generate_release_notes: false
79+
80+
- uses: actions/attest-build-provenance@v2
81+
with:
82+
subject-path: "${{ env.MODULE_NAME }}.zip"

0 commit comments

Comments
 (0)