Skip to content

Commit

Permalink
ci(linux-x64): 增加linux-x64的运行器, 并做相关适配
Browse files Browse the repository at this point in the history
  • Loading branch information
LuSrackhall committed Aug 29, 2024
1 parent a26bdb1 commit 48651ab
Showing 1 changed file with 145 additions and 1 deletion.
146 changes: 145 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,37 @@ jobs:
build:
strategy:
matrix:
os: [windows-latest]
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
outputs:
# region ------------Windows start
INSTALLER_NAME_X64_SETUP_EXE: ${{ env.INSTALLER_NAME_X64_SETUP_EXE }}
INSTALLER_NAME_X64_ZIP: ${{ env.INSTALLER_NAME_X64_ZIP }}
SHA256_X64_SETUP_EXE: ${{ env.SHA256_X64_SETUP_EXE }}
MD5_X64_SETUP_EXE: ${{ env.MD5_X64_SETUP_EXE }}
# endregion
# -------------------Windows end

# region ------------Linux start
# ----------------------------------------------------------------------------------------X64_TARGZ
INSTALLER_NAME_X64_TARGZ: ${{ env.INSTALLER_NAME_X64_TARGZ }}
SHA256_X64_TARGZ: ${{ env.SHA256_X64_TARGZ }}
MD5_X64_TARGZ: ${{ env.MD5_X64_TARGZ }}
# ----------------------------------------------------------------------------------------X64_APPIMAGE
INSTALLER_NAME_X64_APPIMAGE: ${{ env.INSTALLER_NAME_X64_APPIMAGE }}
SHA256_X64_APPIMAGE: ${{ env.SHA256_X64_APPIMAGE }}
MD5_X64_APPIMAGE: ${{ env.MD5_X64_APPIMAGE }}
# ----------------------------------------------------------------------------------------X64_DEB
INSTALLER_NAME_X64_DEB: ${{ env.INSTALLER_NAME_X64_DEB }}
SHA256_X64_DEB: ${{ env.SHA256_X64_DEB }}
MD5_X64_DEB: ${{ env.MD5_X64_DEB }}
# endregion
# -------------------Linux end

# region ------------MacOS start

# endregion
# -------------------MacOS end

steps:
- name: Checkout code
Expand All @@ -39,13 +63,18 @@ jobs:
working-directory: frontend # 以项目根目录为起点,指定对应目录
run: npm install # 安装前端依赖

################################################# Win start ######################################################
# region

- name: Build Application (Windows x64)
if: matrix.os == 'windows-latest'
shell: bash # 我不喜欢powershell(即使是在windows下) # 这个指定, 应该会让我们使用git-bash。
run: | # 指定此run为多个命令依次执行
cd sdk
make win
- name: Find the generated installer (Windows x64)
if: matrix.os == 'windows-latest'
working-directory: frontend/dist/electron/Packaged
shell: bash # 由于我们下方要使用的find命令, powershell中没有(更重要的是, 我不喜欢powershell) # 这个指定, 应该会让我们使用git-bash。
run: |
Expand Down Expand Up @@ -77,13 +106,104 @@ jobs:
# -----------------------------------------------------------------------------------------------------ZIP end
- name: Calculate File Hashes (Windows x64)
if: matrix.os == 'windows-latest'
shell: bash
run: |
SHA256_X64_SETUP_EXE=$(sha256sum frontend/dist/electron/Packaged/${{ env.INSTALLER_NAME_X64_SETUP_EXE }} | awk '{print $1}')
MD5_X64_SETUP_EXE=$(md5sum frontend/dist/electron/Packaged/${{ env.INSTALLER_NAME_X64_SETUP_EXE }} | awk '{print $1}')
echo "SHA256_X64_SETUP_EXE=$SHA256_X64_SETUP_EXE" >> $GITHUB_ENV
echo "MD5_X64_SETUP_EXE=$MD5_X64_SETUP_EXE" >> $GITHUB_ENV
# ------------------------------------------------------/////////////////////

# - name: Build Application (Windows arm64)

# - name: Find the generated installer (Windows arm64)

# - name: Calculate File Hashes (Windows arm64)

# endregion
################################################# Win end ######################################################

############################################### Linux start ######################################################
# region

- name: Build Application (Linux x64)
if: matrix.os == 'ubuntu-latest'
shell: bash
run: | # 指定此run为多个命令依次执行
cd sdk
sudo apt-get update
sudo apt install gcc libc6-dev
sudo apt install libx11-dev xorg-dev libxtst-dev
sudo apt install xsel xclip
sudo apt install libpng++-dev
sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev
sudo apt install libasound2-dev
make linux
- name: Find the generated installer (Linux x64)
if: matrix.os == 'ubuntu-latest'
working-directory: frontend/dist/electron/Packaged
shell: bash # 由于我们下方要使用的find命令, powershell中没有(更重要的是, 我不喜欢powershell) # 这个指定, 应该会让我们使用git-bash。
run: |
# 由于find -name 'KeyTone-Setup-*-win.exe'得到的结果为./KeyTone-Setup-*-win.exe , 而我们不需要./ , 因此使用basename提取文件名
# 由于大部分人的计算机是x64架构的(现在x86的纯32位系统几乎没人用了, 因此我的应用只支持64位的机器), 所以默认不显示架构。(我们通过正则表达式来除掉这部分)(主要显示了3中形式太乱, 如amd64、x64、x86_64)
# * 这部分正则的原理是, 替换: 将 `从win末尾的任意字符开头至遇到第一个.后的所有内容` 使用`win.` 来替换。
# ----------------------------------------------------------------------------------------INSTALLER_NAME_X64_TARGZ
INSTALLER_NAME_X64_TARGZ=$(basename $(find -name 'KeyTone-*-win*exe'))
# ----------为避免出现amd64、x86_64、x64等多种x64的cpu架构表示方式, 我仅按x64为默认名来显示此类cpu架构名---start
# * 我们仅按x64为默认名来显示的话, 就存在其结果本身就是x64这个名称的情况, 那此时仍通过 mv 重命名就会发生报错了。
# * 因为, 在进行mv时, 遇到移动前后名称相同的情况, 是会报错的。
# * 所以, 我们为了不报错, 我们尝试通过`-f`来强制重命名来解决。(失败)<因为-f解决覆盖问题, 但无法处理此情况>
# * 最终, 借助shell中的判断语句来解决
# ----------------------------------------------------------------------------------------INSTALLER_NAME_X64_TARGZ
if [ "$INSTALLER_NAME_X64_TARGZ" != "$(echo $INSTALLER_NAME_X64_TARGZ | sed 's/linux[^.]*\./linux-x64./')" ]; then
mv -f $INSTALLER_NAME_X64_TARGZ $(echo $INSTALLER_NAME_X64_TARGZ | sed 's/linux[^.]*\./linux-x64./')
INSTALLER_NAME_X64_TARGZ=$(echo $INSTALLER_NAME_X64_TARGZ | sed 's/linux[^.]*\./linux-x64./')
fi
echo "INSTALLER_NAME_X64_TARGZ=$INSTALLER_NAME_X64_TARGZ" >> $GITHUB_ENV
# ----------------------------------------------------------------------------------------INSTALLER_NAME_X64_APPIMAGE
if [ "$INSTALLER_NAME_X64_APPIMAGE" != "$(echo $INSTALLER_NAME_X64_APPIMAGE | sed 's/linux[^.]*\./linux-x64./')" ]; then
mv -f $INSTALLER_NAME_X64_APPIMAGE $(echo $INSTALLER_NAME_X64_APPIMAGE | sed 's/linux[^.]*\./linux-x64./')
INSTALLER_NAME_X64_APPIMAGE=$(echo $INSTALLER_NAME_X64_APPIMAGE | sed 's/linux[^.]*\./linux-x64./')
fi
echo "INSTALLER_NAME_X64_APPIMAGE=$INSTALLER_NAME_X64_APPIMAGE" >> $GITHUB_ENV
# ----------------------------------------------------------------------------------------INSTALLER_NAME_X64_DEB
if [ "$INSTALLER_NAME_X64_DEB" != "$(echo $INSTALLER_NAME_X64_DEB | sed 's/linux[^.]*\./linux-x64./')" ]; then
mv -f $INSTALLER_NAME_X64_DEB $(echo $INSTALLER_NAME_X64_DEB | sed 's/linux[^.]*\./linux-x64./')
INSTALLER_NAME_X64_DEB=$(echo $INSTALLER_NAME_X64_DEB | sed 's/linux[^.]*\./linux-x64./')
fi
echo "INSTALLER_NAME_X64_DEB=$INSTALLER_NAME_X64_DEB" >> $GITHUB_ENV
- name: Calculate File Hashes (Linux x64)
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
# ----------------------------------------------------------------------------------------X64_TARGZ
SHA256_X64_TARGZ=$(sha256sum frontend/dist/electron/Packaged/${{ env.INSTALLER_NAME_X64_TARGZ }} | awk '{print $1}')
MD5_X64_TARGZ=$(md5sum frontend/dist/electron/Packaged/${{ env.INSTALLER_NAME_X64_TARGZ }} | awk '{print $1}')
echo "SHA256_X64_TARGZ=$SHA256_X64_TARGZ" >> $GITHUB_ENV
echo "MD5_X64_TARGZ=$MD5_X64_TARGZ" >> $GITHUB_ENV
# ----------------------------------------------------------------------------------------X64_APPIMAGE
SHA256_X64_APPIMAGE=$(sha256sum frontend/dist/electron/Packaged/${{ env.INSTALLER_NAME_X64_APPIMAGE }} | awk '{print $1}')
MD5_X64_APPIMAGE=$(md5sum frontend/dist/electron/Packaged/${{ env.INSTALLER_NAME_X64_APPIMAGE }} | awk '{print $1}')
echo "SHA256_X64_APPIMAGE=$SHA256_X64_APPIMAGE" >> $GITHUB_ENV
echo "MD5_X64_APPIMAGE=$MD5_X64_APPIMAGE" >> $GITHUB_ENV
# ----------------------------------------------------------------------------------------X64_DEB
SHA256_X64_DEB=$(sha256sum frontend/dist/electron/Packaged/${{ env.INSTALLER_NAME_X64_DEB }} | awk '{print $1}')
MD5_X64_DEB=$(md5sum frontend/dist/electron/Packaged/${{ env.INSTALLER_NAME_X64_DEB }} | awk '{print $1}')
echo "SHA256_X64_DEB=$SHA256_X64_DEB" >> $GITHUB_ENV
echo "MD5_X64_DEB=$MD5_X64_DEB" >> $GITHUB_ENV
# endregion
############################################### Linux end ######################################################

############################################### MacOS start ######################################################
# region

# endregion
############################################### MacOS end ######################################################

- name: Upload Build Artifact (ALL)
# TIPS: Artifact 中, 通过手动点击, 下载的打包结果的名称(无论名称如何设置, 都会给你加载.zip后缀的, 这是其预期的行为)
# > 虽然单看大小并没有被压缩, 但确实是套了一层文件夹后的压缩格式, 而不是简单的仅更改了后缀名。可通过hash值验证:
Expand Down Expand Up @@ -133,12 +253,36 @@ jobs:
* `${{ needs.build.outputs.SHA256_X64_SETUP_EXE }}`
`${{ needs.build.outputs.INSTALLER_NAME_X64_TARGZ }}` is:
* `${{ needs.build.outputs.SHA256_X64_TARGZ }}`
`${{ needs.build.outputs.INSTALLER_NAME_X64_APPIMAGE }}` is:
* `${{ needs.build.outputs.SHA256_X64_APPIMAGE }}`
`${{ needs.build.outputs.INSTALLER_NAME_X64_DEB }}` is:
* `${{ needs.build.outputs.SHA256_X64_DEB }}`
##### The MD5 hash sum
`${{ needs.build.outputs.INSTALLER_NAME_X64_SETUP_EXE }}` is:
* `${{ needs.build.outputs.MD5_X64_SETUP_EXE }}`
`${{ needs.build.outputs.INSTALLER_NAME_X64_TARGZ }}` is:
* `${{ needs.build.outputs.MD5_X64_TARGZ }}`
`${{ needs.build.outputs.INSTALLER_NAME_X64_APPIMAGE }}` is:
* `${{ needs.build.outputs.MD5_X64_APPIMAGE }}`
`${{ needs.build.outputs.INSTALLER_NAME_X64_DEB }}` is:
* `${{ needs.build.outputs.MD5_X64_DEB }}`
### Changelogs
- name: Upload Build Artifact to Release
Expand Down

0 comments on commit 48651ab

Please sign in to comment.