-
Notifications
You must be signed in to change notification settings - Fork 8
123 lines (109 loc) · 3.65 KB
/
compress-and-release.yml
File metadata and controls
123 lines (109 loc) · 3.65 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
name: Compress and Release
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'mux/*.json'
- 'tr_map.txt'
- '.github/workflows/compress-and-release-lang.yml'
pull_request:
paths:
- 'mux/*.json'
- 'tr_map.txt'
- '.github/workflows/compress-and-release-lang.yml'
jobs:
compress-and-upload:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Derive tag, name, and target
shell: bash
run: |
set -eu
TS="$(date +'%Y%m%d-%H%M%S')"
SHORT_SHA="$(git rev-parse --short HEAD)"
NOW_DATE="$(date +'%Y-%m-%d %H:%M:%S')"
case "${{ github.event_name }}" in
workflow_dispatch)
TAG_NAME="release-${TS}"
RELEASE_NAME="Language Pack - ${NOW_DATE}"
TARGET="${{ github.sha }}"
;;
push)
TAG_NAME="release-main-${SHORT_SHA}-${TS}"
RELEASE_NAME="Language Pack (main @ ${SHORT_SHA}) - ${NOW_DATE}"
TARGET="${{ github.sha }}"
;;
pull_request)
PR="${{ github.event.pull_request.number }}"
TAG_NAME="pr-${PR}-${SHORT_SHA}-${TS}"
RELEASE_NAME="Language Pack (PR #${PR}) - ${NOW_DATE}"
TARGET="${{ github.event.pull_request.head.sha }}"
;;
esac
{
echo "TAG_NAME=$TAG_NAME"
echo "RELEASE_NAME=$RELEASE_NAME"
echo "TARGET_COMMITISH=$TARGET"
} >> "$GITHUB_ENV"
- name: Build lang.muxzip
shell: bash
run: |
set -euxo pipefail
MAP="tr_map.txt"
SRC="mux"
test -f "$MAP"
test -d "$SRC"
mkdir -p artifacts
STAGE="$(mktemp -d)"
DEST="$STAGE/mnt/mmc/MUOS/language"
mkdir -p "$DEST"
added=0
while IFS= read -r -d '' f; do
code="${f##*/}"; code="${code%.json}"
if ! name="$(awk -F: -v k="$code" '
$1==k {
n=$2
sub(/^[[:space:]]+/,"",n)
sub(/[[:space:]\r]+$/,"",n)
print n
found=1
}
END { if (!found) exit 1 }
' "$MAP" 2>/dev/null)"; then
echo "::notice::Skipped $code (no mapping in tr_map.txt)"
continue
fi
cp "$f" "$DEST/$name.json"
echo "Added: $code -> $name"
added=$((added+1))
done < <(find "$SRC" -type f -name '*.json' -print0 | sort -z)
echo "Total mapped files added: $added"
if [ "$added" -eq 0 ]; then
echo "::error::No mapped languages found."
exit 1
fi
( cd "$STAGE" && zip -r9X lang.muxzip mnt )
mv "$STAGE/lang.muxzip" artifacts/lang.muxzip
unzip -l artifacts/lang.muxzip || true
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: lang.muxzip
path: artifacts/lang.muxzip
if-no-files-found: error
retention-days: 14
- name: Create GitHub Release
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG_NAME }}
name: ${{ env.RELEASE_NAME }}
target_commitish: ${{ env.TARGET_COMMITISH }}
files: artifacts/lang.muxzip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}