From aa9c5603188b41b412da889ea32e3dae43fc1930 Mon Sep 17 00:00:00 2001 From: Horror Proton <107091537+horror-proton@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:07:22 +0800 Subject: [PATCH] chore: add nightly build workflow --- .github/workflows/release-nightly-ota.yml | 121 ++++++++++++++++++++++ .github/workflows/release-ota.yml | 32 ++++-- tools/OTAPacker/build.sh | 20 ++-- 3 files changed, 153 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/release-nightly-ota.yml diff --git a/.github/workflows/release-nightly-ota.yml b/.github/workflows/release-nightly-ota.yml new file mode 100644 index 0000000000..6dd63ce94c --- /dev/null +++ b/.github/workflows/release-nightly-ota.yml @@ -0,0 +1,121 @@ +name: release-nightly-ota + +on: + workflow_dispatch: + inputs: + ref: + description: 'Commit to build (git checkout)' + type: string + required: true + limit: + description: 'Number of releases to fetch from MaaAssistantArknights' + required: false + default: 30 + type: number + limit_2: + description: 'Number of releases to fetch from MaaRelease' + required: false + default: 30 + +jobs: + build-win-nightly: + runs-on: windows-latest + outputs: + hash: ${{ steps.set_hash.outputs.hash }} + steps: + - uses: actions/checkout@v3 + with: + # repository: 'MaaAssistantArknights/MaaAssistantArknights' + submodules: recursive + #ref: ${{ inputs.ref }} + fetch-depth: 0 + - name: Checkout ref + run: | + git checkout --progress --recurse-submodules ${{ inputs.ref || 'dev' }} + - name: Set hash + id: set_hash + run: | + # "hash=c$(Get-Date -Format 'yyMMdd')-$(git rev-parse --short HEAD)" >> $env:GITHUB_OUTPUT + "hash=$(git describe --tags --long)" >> $env:GITHUB_OUTPUT + - name: Run './build.cmd DevBuild' + run: | + $env:GITHUB_WORKFLOW='dev-build-win' # pretend this is a dev-build-win workflow + $env:MAA_BUILDER_MAA_VERSION="${{steps.set_hash.outputs.hash}}" + ./build.cmd DevBuild + env: + Reason: 'Build nightly version' + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/upload-artifact@v3 + with: + name: MAA-win-x64 + path: artifacts + + make-ota: + needs: build-win-nightly + runs-on: ubuntu-latest + steps: + - run: echo ${{ needs.build-win-nightyl.outputs.hash }} + - name: "Fetch MaaRelease" + uses: actions/checkout@v3 + with: + repository: ${{ format('{0}/{1}', github.repository_owner, 'MaaRelease') }} + path: MaaRelease + fetch-depth: 0 + token: ${{ secrets.MAARELEASE_RELEASE }} + - uses: actions/checkout@v3 + with: + path: MaaAssistantArknights + - uses: actions/download-artifact@v3 + with: + name: MAA-win-x64 + path: ${{ format('{0}/{1}', 'build-ota', needs.build-win-nightly.outputs.hash) }} + - name: "Fetch release info" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + mkdir -pv build-ota && cd build-ota + cd ${{ needs.build-win-nightly.outputs.hash }} + mkdir -pv content + unzip -q *.zip -d content + cd .. + + gh release list --repo 'MaaAssistantArknights/MaaAssistantArknights' --limit ${{ inputs.limit || 30 }} | tee ./release_maa.txt + gh release list --repo "${{ github.repository_owner }}/MaaRelease" --limit ${{ inputs.limit_2 || 30 }} | tee ./release_mr.txt + echo ${{ needs.build-win-nightly.outputs.hash }} > ./config + + cat ./release_maa.txt | awk '{ print $1 }' > ./tags_maa.txt + cat ./release_mr.txt | awk '{ print $1 }' > ./tags_mr.txt + + comm <(sort ./tags_maa.txt) <(sort ./tags_mr.txt) | awk '{ print $1 }' >> ./config + + echo "config:" + cat ./config + + echo "release_tag=$(head -n 1 ./config)" >> $GITHUB_ENV + - name: "Build OTA" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd build-ota + $GITHUB_WORKSPACE/MaaAssistantArknights/tools/OTAPacker/build.sh 'MaaAssistantArknights/MaaAssistantArknights' ./config "${{ github.repository_owner }}/MaaRelease" + mv -v ${{ needs.build-win-nightly.outputs.hash }}/*.zip ./MAA-${{ env.release_tag }}-win-x64.zip + - name: "Commit and setup tag" + run: | + cd MaaRelease + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + git checkout --orphan temp + git rm -rf . + git commit --allow-empty --message ${{ env.release_tag }} + git tag ${{ env.release_tag }} || exit 0 # do nothing if the tag already exists + git push --tags $PUSH_REMOTE + - name: "Upload to MaaRelease" + uses: svenstaro/upload-release-action@v2 + with: + repo_name: ${{ format('{0}/{1}', github.repository_owner, 'MaaRelease') }} + repo_token: ${{ secrets.MAARELEASE_RELEASE }} + file_glob: true + file: build-ota/*.zip + tag: ${{ env.release_tag }} + prerelease: true + overwrite: true diff --git a/.github/workflows/release-ota.yml b/.github/workflows/release-ota.yml index 2c8ad690f0..fd3ebca8fa 100644 --- a/.github/workflows/release-ota.yml +++ b/.github/workflows/release-ota.yml @@ -6,10 +6,14 @@ on: workflow_dispatch: inputs: limit: - description: 'Number of releases to fetch, 2 at least' + description: 'Number of releases to fetch from MaaAssistantArknights, 2 at least' required: false - default: 51 + default: 31 type: number + limit_2: + description: 'Number of releases to fetch from MaaRelease' + required: false + default: 30 jobs: make-ota: @@ -30,26 +34,36 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | mkdir -pv build-ota && cd build-ota - gh release list --repo 'MaaAssistantArknights/MaaAssistantArknights' --limit ${{ inputs.limit || 51 }} | tee ./release_list.txt - echo "prerelease=$([ $(head -n 1 release_list.txt | awk '{ print $2}') = 'Pre-release' ] && echo true || echo false)" >> $GITHUB_ENV - cat ./release_list.txt | awk '{ print $1 }' > ./releases - echo "release_tag=$(head -n 1 ./releases)" >> $GITHUB_ENV + gh release list --repo 'MaaAssistantArknights/MaaAssistantArknights' --limit ${{ inputs.limit || 31 }} | tee ./release_maa.txt + gh release list --repo "${{ github.repository_owner }}/MaaRelease" --limit ${{ inputs.limit_2 || 30 }} | tee ./release_mr.txt + head -n 1 ./release_maa.txt | awk '{ print $1 }' > ./config + + tail -n +1 ./release_maa.txt | awk '{ print $1 }' > ./tags_maa.txt + cat ./release_mr.txt | awk '{ print $1 }' > ./tags_mr.txt + + comm <(sort ./tags_maa.txt) <(sort ./tags_mr.txt) | awk '{ print $1 }' >> ./config + + echo "config:" + cat ./config + + echo "prerelease=$([ $(head -n 1 release_maa.txt | awk '{ print $2}') = 'Pre-release' ] && echo true || echo false)" >> $GITHUB_ENV + echo "release_tag=$(head -n 1 ./config)" >> $GITHUB_ENV - name: "Build OTA" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | cd build-ota - $GITHUB_WORKSPACE/MaaAssistantArknights/tools/OTAPacker/build.sh 'MaaAssistantArknights/MaaAssistantArknights' ./releases + $GITHUB_WORKSPACE/MaaAssistantArknights/tools/OTAPacker/build.sh 'MaaAssistantArknights/MaaAssistantArknights' ./config - name: "Commit and setup tag" run: | cd MaaRelease git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' - git checkout --orphan temp + git checkout --orphan __temp git rm -rf . git commit --allow-empty --message ${{ env.release_tag }} git tag ${{ env.release_tag }} || exit 0 # do nothing if the tag already exists - git push --tags $PUSH_REMOTE + git push --tags env: PUSH_REMOTE: https://github-actions[bot]:${{ secrets.MAARELEASE_RELEASE }}@github.com/${{ github.repository_owner }}/MaaRelease - name: "Upload to MaaRelease" diff --git a/tools/OTAPacker/build.sh b/tools/OTAPacker/build.sh index 02133c25d8..011b2f082a 100755 --- a/tools/OTAPacker/build.sh +++ b/tools/OTAPacker/build.sh @@ -2,10 +2,7 @@ source_repo=$1 releases_txt="$2" - -ghrepo() { - gh $@ --repo $source_repo -} +source_repo_fallback=$3 working_dir="$(pwd)" echo "working_dir: $working_dir" @@ -15,18 +12,19 @@ script_dir="$(dirname $(realpath "$0"))" latest_tag=$(head -n 1 "$releases_txt") while read tag; do - ( + if [ ! -d "$tag"/content ]; then mkdir -pv "$tag" cd "$tag" echo "Downloading $tag" - ghrepo release download "$tag" --pattern "MAA-$tag-win-x64.zip" --pattern "MaaBundle-$tag.zip" --clobber + gh release download "$tag" --repo $source_repo --pattern "MAA-$tag-win-x64.zip" --pattern "MaaBundle-$tag.zip" --clobber \ + || gh release download "$tag" --repo $source_repo_fallback --pattern "MAA-$tag-win-x64.zip" --pattern "MaaBundle-$tag.zip" --clobber mkdir -pv 'content' - echo "Unzip" *.zip - unzip -qq -O gbk -o "*.zip" -d 'content' + unzip -q -O gbk -o "*.zip" -d 'content' rm -fv *.zip - ) - - cd $working_dir + cd $working_dir + else + echo "$tag"/content/ already exists + fi if [[ "$tag" == "$latest_tag" ]]; then cd "$latest_tag"/content/