Skip to content

Archiver

Archiver #59

Workflow file for this run

name: Archiver
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
inputs:
Version:
description: '"Version" of WSA to archive.'
type: string
URL:
description: '"URL" of WSA to archive. (Higher priority than "UpdateID")'
type: string
UpdateID:
description: '"UpdateID" of WSA in Microsoft Store. It maybe replace "Version" to right version.'
type: string
jobs:
archive:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python 🏭
uses: actions/setup-python@v4
with:
check-latest: true
python-version: '3.x'
- name: Install Ubuntu Dependencies 🧑‍🏭
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: e2fsprogs unzip qemu-utils aapt jq erofs-utils
version: 1.0
- name: Install Python dependencies 🧑‍🏭
run:
pip install requests
- name: Set UP Dispatch 📝
id: version
run: |
cd ${{ github.workspace }}
sudo chmod 766 UpdateInfo.cfg
Version=$(sed -n 's/^Version=//p' UpdateInfo.cfg)
UpdateID=$(sed -n 's/^UpdateID=//p' UpdateInfo.cfg)
URL=$(sed -n 's/^URL=//p' UpdateInfo.cfg)
if [ -n "${{ inputs.Version }}" ]; then
echo "Version=${{ inputs.Version }}" > UpdateInfo.cfg
else
echo "Version=$Version" > UpdateInfo.cfg
fi
if [ -n "${{ inputs.UpdateID }}" ]; then
echo "UpdateID=${{ inputs.UpdateID }}" >> UpdateInfo.cfg
else
echo "UpdateID=$UpdateID" >> UpdateInfo.cfg
fi
if [ -n "${{ inputs.URL }}" ]; then
echo "URL=${{ inputs.URL }}" >> UpdateInfo.cfg
else
echo "URL=$URL" >> UpdateInfo.cfg
fi
- name: Download 📥
id: download
run: |
cd ${{ github.workspace }}
python3 Archiver.py || echo "failed=true" >> $GITHUB_OUTPUT
- name: Check if release exists 🤔
if: steps.download.outputs.failed != 'true'
id: check_release
run: |
latest_tag=$(curl -sL https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')
response=$(curl -s -H "Authorization: Bearer ${{ secrets.PAT }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.download.outputs.Version }}")
if [ ${#response} -gt 200 ]; then
echo "Release already exists"
echo "release_exists=true" >> $GITHUB_OUTPUT
else
echo "Release does not exist"
echo "release_exists=false" >> $GITHUB_OUTPUT
if [ "$latest_tag" < "${{ steps.download.outputs.Version }}" ]; then
echo "isPrerelease=true" >> $GITHUB_OUTPUT
else
echo "isPrerelease=false" >> $GITHUB_OUTPUT
fi
fi
- name: Upload result 📤
id: result
if: steps.check_release.outputs.release_exists == 'false'
uses: actions/upload-artifact@v1
with:
name: ${{ steps.download.outputs.Filename }}
path: ${{ github.workspace }}/download/${{ steps.download.outputs.Filename }}
- name: File Checksum ✔️
id: hash
if: steps.check_release.outputs.release_exists == 'false'
run: |
filedir="${{ github.workspace }}/download/${{ steps.download.outputs.Filename }}"
md5_hash=$(md5sum "$filedir" | cut -d ' ' -f 1)
sha256_hash=$(sha256sum "$filedir" | cut -d ' ' -f 1)
md5_hash_lower=$(echo "$md5_hash" | tr '[:upper:]' '[:lower:]')
sha256_hash_lower=$(echo "$sha256_hash" | tr '[:upper:]' '[:lower:]')
echo "MD5=$md5_hash_lower" >> $GITHUB_OUTPUT
echo "SHA256=$sha256_hash_lower" >> $GITHUB_OUTPUT
echo "MD5=$md5_hash_lower"
echo "SHA256=$sha256_hash_lower"
- name: Update build to release 🤌
if: steps.check_release.outputs.isPrerelease == 'false'
uses: softprops/[email protected]
with:
files: ${{ github.workspace }}/download/${{ steps.download.outputs.Filename }}
fail_on_unmatched_files: true
append_body: true
tag_name: ${{ steps.download.outputs.Version }}
body: |
## File name
```
${{ github.workspace }}/download/${{ steps.download.outputs.Filename }}
```
## Hashes
- MD5
```
${{ steps.hash.outputs.MD5 }}
```
- SHA256
```
${{ steps.hash.outputs.SHA256 }}
```
token: ${{ secrets.PAT }}
- name: Update build to Pre-release 🤌
if: steps.check_release.outputs.isPrerelease == 'true'
uses: softprops/[email protected]
with:
files: ${{ github.workspace }}/download/${{ steps.download.outputs.Filename }}
fail_on_unmatched_files: true
append_body: true
prerelease: true
tag_name: ${{ steps.download.outputs.Version }}
body: |
## File name
```
${{ github.workspace }}/download/${{ steps.download.outputs.Filename }}
```
## Hashes
- MD5
```
${{ steps.hash.outputs.MD5 }}
```
- SHA256
```
${{ steps.hash.outputs.SHA256 }}
```
token: ${{ secrets.PAT }}
- name: Check Image Info 📝
id: info
run: |
cd ${{ github.workspace }}
sudo chmod 700 CheckImage.sh
sudo ./CheckImage.sh || true
body=$(curl -s -H "Authorization: Bearer ${{ secrets.PAT }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.download.outputs.Version }}" \
| jq -r '.body')
if [[ $body == *"## Details"* ]]; then
echo "update=false" >> $GITHUB_OUTPUT
elif [ -e ./download/INFO.md ]; then
echo "INFO<<EOF" >> $GITHUB_OUTPUT
cat ./download/INFO.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "update=true" >> $GITHUB_OUTPUT
else
echo "update=false" >> $GITHUB_OUTPUT
fi
- name: Update Image Info 🤌
if: steps.info.outputs.update == 'true'
uses: softprops/[email protected]
with:
append_body: true
tag_name: ${{ steps.download.outputs.Version }}
body: |
${{ steps.info.outputs.INFO }}
token: ${{ secrets.PAT }}