From 6ebdd3390fc14ea92d9cb0c81118a02f9ab7a511 Mon Sep 17 00:00:00 2001 From: Klop233 <3337913379@qq.com> Date: Wed, 3 Apr 2024 21:09:03 +0800 Subject: [PATCH] update CI --- .github/workflows/build_1_20_4.yml | 132 ++++++++++++++++++----------- scripts/GetReleaseInfo.sh | 58 +++++++++++++ 2 files changed, 141 insertions(+), 49 deletions(-) create mode 100644 scripts/GetReleaseInfo.sh diff --git a/.github/workflows/build_1_20_4.yml b/.github/workflows/build_1_20_4.yml index bc78b2a..17b5660 100644 --- a/.github/workflows/build_1_20_4.yml +++ b/.github/workflows/build_1_20_4.yml @@ -18,53 +18,87 @@ permissions: write-all jobs: build: runs-on: ubuntu-latest - + if: github.event.pull_request.merged || github.event_name == 'push' || github.event_name == 'workflow_dispatch' steps: - - uses: actions/checkout@v3 - - name: Set up git - run: git config --global user.email "noreply@github.com" && git config --global user.name "ci" - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - name: Make gradlew executable - run: chmod 777 ./gradlew - - name: Setup project - uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 - with: - arguments: applyPatches - - name: Build project to paperclip jar - uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 - with: - arguments: createReobfPaperclipJar - - name: Capture build artifacts - uses: actions/upload-artifact@v3 - with: - name: Artifacts - path: build/libs/ - - name: Publish All - run: | - echo "GITHUB_USERNAME=LuminolCI" >> $GITHUB_ENV - export GITHUB_USERNAME=LuminolCI - echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV - export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} - ./gradlew publish -PpublishDevBundle=true - - name: Rename jar file - run: mv build/libs/luminol-paperclip-1.20.4-R0.1-SNAPSHOT-reobf.jar build/libs/luminol-1.20.4-paperclip.jar - - name: Release Artifacts - uses: svenstaro/upload-release-action@v2 - with: - release_name: "Luminol MC1.20.4 - ${{ github.event.repository.updated_at}}" - tag: "1.20.4-${{ github.run_id }}" - repo_token: "${{ secrets.GITHUB_TOKEN }}" - file: "build/libs/luminol-1.20.4-paperclip.jar" - file_glob: true - prerelease: true - - name: Push to API - continue-on-error: true - if: "!contains(github.event.commits[0].message, '[release-skip]')" - env: - secret_v2: ${{ secrets.API_V2_PUSH_TOKEN }} - tag: ${{ env.tag }} - run: sh scripts/PushToAPI.sh + - name: Get repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Get JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'zulu' + - name: Setup Git Config + run: | + git config --global user.email "ci@leavesmc.top" + git config --global user.name "Leaves CI" + - name: Apply Patches + uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7 + with: + arguments: applyPatches + - name: Create Paperclip Jar + uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7 + with: + arguments: createReobfPaperclipJar + - name: Publish API + continue-on-error: true + uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7 + with: + arguments: publish -PleavesUsername=${{ secrets.REPO_USERNAME }} -PleavesPassword=${{ secrets.REPO_PASSWORD }} + - name: Create Configuration + continue-on-error: true + uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7 + with: + arguments: createLeavesConfig + - name: Push Configuration + continue-on-error: true + run: | + mkdir --parents "$HOME/.ssh" + ssh-keyscan -H "github.com" > "$HOME/.ssh/known_hosts" + echo "${{ secrets.CONFIG_DEPLOY_KEY }}" > "$HOME/.ssh/deploy.key" + chmod 400 "$HOME/.ssh/deploy.key" + export GIT_SSH_COMMAND="ssh -i $HOME/.ssh/deploy.key" + git clone git@github.com:LeavesMC/Configuration.git configuration -b Leaves + cp run/leaves.yml configuration/leaves.yml -f + cd configuration + git add leaves.yml + git commit leaves.yml -m "$(date -u +"%Y-%m-%dT%H:%M:%SZ") + https://github.com/LeavesMC/Leaves/commit/$(cd .. && git rev-parse HEAD)" + git push origin HEAD:Leaves + - name: Get Release Info + run: sh scripts/GetReleaseInfo.sh + - name: Create Release + if: "!contains(github.event.commits[0].message, '[ci-skip]')" + uses: ncipollo/release-action@v1.12.0 + with: + artifacts: ${{ env.jar }} + bodyFile: ${{ env.info }} + tag: ${{ env.tag }} + name: ${{ env.name }} + prerelease: ${{ env.pre }} + token: ${{ secrets.GITHUB_TOKEN }} + makeLatest: ${{ env.make_latest }} + - name: Delete Draft Releases + uses: hugo19941994/delete-draft-releases@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# - name: Github Releases To Discord +# continue-on-error: true +# uses: tsickert/discord-webhook@v5.3.0 +# with: +# webhook-url: ${{ secrets.DISCORD_WEBHOOK }} +# raw-data: ${{ env.discordmes }} + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ env.jar }} + path: ${{ env.jar }} + - name: Push to Api + continue-on-error: true + if: "!contains(github.event.commits[0].message, '[release-skip]')" + env: + secret: ${{ secrets.API_PUSH_TOKEN }} + secret_v2: ${{ secrets.API_V2_PUSH_TOKEN }} + tag: ${{ env.tag }} + run: sh scripts/PushToAPI.sh diff --git a/scripts/GetReleaseInfo.sh b/scripts/GetReleaseInfo.sh new file mode 100644 index 0000000..64bb3b6 --- /dev/null +++ b/scripts/GetReleaseInfo.sh @@ -0,0 +1,58 @@ +sha1() { + sha1sum $1 | awk '{print $1}' +} + +md5() { + md5sum $1 | awk '{print $1}' +} + +prop() { + grep "${1}" gradle.properties | cut -d'=' -f2 | sed 's/\r//' +} + +commitid=$(git log --pretty='%h' -1) +mcversion=$(prop mcVersion) +gradleVersion=$(prop version) +preVersion=$(prop preVersion) +tagid="$mcversion-$commitid" +jarName="luminol-$mcversion.jar" +luminolid="Luminol-$commitid" +releaseinfo="releaseinfo.md" +#discordmes="discordmes.json" +make_latest=$([ $preVersion = "true" ] && echo "false" || echo "true") + +rm -f $discordmes +rm -f $releaseinfo + +mv build/libs/Luminol-paperclip-$gradleVersion-reobf.jar $jarName +echo "name=$luminolid" >> $GITHUB_ENV +echo "tag=$tagid" >> $GITHUB_ENV +echo "jar=$jarName" >> $GITHUB_ENV +echo "info=$releaseinfo" >> $GITHUB_ENV +#echo "discordmes=$discordmes" >> $GITHUB_ENV +echo "pre=$preVersion" >> $GITHUB_ENV +echo "make_latest=$make_latest" >> $GITHUB_ENV + +echo "$luminolid [![download](https://img.shields.io/github/downloads/LuminolMC/Luminol/$tagid/total?color=0)](https://github.com/LuminolMC/Luminol/releases/download/$tagid/$jarName)" >> $releaseinfo +echo "=====" >> $releaseinfo +echo "" >> $releaseinfo +if [ $preVersion = "true" ]; then + echo "> This is an early, experimental build. It is only recommended for usage on test servers and should be used with caution." >> $releaseinfo + echo "> **Backups are mandatory!**" >> $releaseinfo + echo "" >> $releaseinfo +fi +echo "### Commit Message" >> $releaseinfo + +number=$(git log --oneline master ^`git describe --tags --abbrev=0` | wc -l) +echo "$(git log --pretty='> [%h] %s' -$number)" >> $releaseinfo + +echo "" >> $releaseinfo +echo "### Checksum" >> $releaseinfo +echo "| File | $jarName |" >> $releaseinfo +echo "| ---- | ---- |" >> $releaseinfo +echo "| MD5 | `md5 $jarName` |" >> $releaseinfo +echo "| SHA1 | `sha1 $jarName` |" >> $releaseinfo + +#echo -n "{\"content\":\"Leaves New Release\",\"embeds\":[{\"title\":\"$leavesid\",\"url\":\"https://github.com/LeavesMC/Leaves/releases/tag/$tagid\",\"fields\":[{\"name\":\"Changelog\",\"value\":\"" >> $discordmes +#echo -n $(git log --oneline --pretty='> [%h] %s\\n' -$number) >> $discordmes +#echo "\",\"inline\":true}]}]}" >> $discordmes \ No newline at end of file