Skip to content

Commit c41432c

Browse files
authored
add action to create Arduino package automatically #191
This repo has been stall for quite a while and there are many PRs unmerged. This PR adds a github action file that automatically pack the repo when commit or pull request. You only need to make sure you have a release tagged as "arduinoPack", then the github action will automatically add repo zip and json into that arduinoPack release. I hope it will simplify the process of improving code in your own repo. You may test it on https://github.com/DeqingSun/arduino_core_ch32/releases/download/arduinoPack/package_ch32v_index_githubActionRelease.json Also the windows installation error has been fixed. WCHISP packed as well. The included WCHISP was compiled with https://github.com/DeqingSun/wchisp/tree/CH375DLL64_access . So if you are using Windows, CH375 (WCH official wchisptool) and LIBUSB both work. openwch/arduino_core_ch32#191
1 parent 4c1f555 commit c41432c

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

.github/workflows/packArduino.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Pack Arduino Action
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
packArduino:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Set release tag name for storage
13+
id: tag
14+
run: |
15+
echo "Release tag name is arduinoPack"
16+
echo "tag=arduinoPack" >> $GITHUB_ENV
17+
echo "Store the github username"
18+
echo "username=${{ github.actor }}" >> $GITHUB_ENV
19+
echo "Store the github branch name"
20+
branch_name=$(echo "${{ github.ref }}" | awk -F'/' '{print $NF}')
21+
echo "branch=${branch_name}" >> $GITHUB_ENV
22+
23+
- name: Get current date and commit hash
24+
id: vars
25+
run: |
26+
date=$(date +'%y.%-m.%-d')
27+
commit=$(git rev-parse --short HEAD)
28+
echo "Date: $date"
29+
echo "Commit: $commit"
30+
echo "date=$date" >> $GITHUB_ENV
31+
echo "commit=$commit" >> $GITHUB_ENV
32+
echo "zip_name=arduino_core_ch32_${date}_${commit}.zip" >> $GITHUB_ENV
33+
echo "zip_basename=arduino_core_ch32_${date}_${commit}" >> $GITHUB_ENV
34+
35+
- name: Pack whole repo excluding hidden files
36+
run: |
37+
echo "Packing the whole repository excluding hidden files..."
38+
mkdir -p ${{ env.zip_basename }}
39+
shopt -s extglob
40+
cp -r !(${{ env.zip_basename }}) ${{ env.zip_basename }}/
41+
zip -r ${{ env.zip_name }} ${{ env.zip_basename }} -x ".*" "*~" "*.zip"
42+
43+
- name: Calculate SHA256 checksum
44+
id: checksum
45+
run: |
46+
echo "Calculating SHA256 checksum..."
47+
sha256sum ${{ env.zip_name }} | awk '{print $1}' > checksum.txt
48+
echo "SHA256 Checksum: $(cat checksum.txt)"
49+
echo "checksum=$(cat checksum.txt)" >> $GITHUB_ENV
50+
51+
- name: Replace content in package_ch32v_index_template.json
52+
run: |
53+
echo "Replacing content in package_ch32v_index_template.json, replace !!!SHA!!! with real SHA256 checksum"
54+
sed -i "s/!!!SHA!!!/${{ env.checksum }}/g" package_ch32v_index_template.json
55+
echo "replace !!!VERSION!!! with date_commit"
56+
sed -i "s/!!!VERSION!!!/${{ env.date }}/g" package_ch32v_index_template.json
57+
echo "replace !!!FILENAME!!! with real filename"
58+
sed -i "s/!!!FILENAME!!!/${{ env.zip_name }}/g" package_ch32v_index_template.json
59+
echo "replace !!!SIZE!!! with real size"
60+
sed -i "s/!!!SIZE!!!/$(stat -c%s ${{ env.zip_name }})/g" package_ch32v_index_template.json
61+
echo "replace !!!URL!!! with soemthing like https://github.com/USERNAME/arduino_core_ch32/arduino_core_ch32/releases/download/TAG/ZIPFILENAME"
62+
sed -i "s/!!!URL!!!/https:\/\/github.com\/${{ env.username }}\/arduino_core_ch32\/releases\/download\/${{ env.tag }}\/${{ env.zip_name }}/g" package_ch32v_index_template.json
63+
echo "copy file to package_ch32v_index_BRANCHNAME.json"
64+
cp package_ch32v_index_template.json package_ch32v_index_${{ env.branch }}.json
65+
echo "-----preview the file------"
66+
cat package_ch32v_index_template.json
67+
68+
69+
- name: Upload asset, make sure you have a release tagged arduinoPack
70+
env:
71+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
run: |
73+
gh release upload ${{ env.tag }} ${{ env.zip_name }} --clobber
74+
gh release upload ${{ env.tag }} package_ch32v_index_${{ env.branch }}.json --clobber

0 commit comments

Comments
 (0)