|
| 1 | +# This workflow allow me to easily upload a certain version of my project within the github tags and externally. |
| 2 | + |
| 3 | +name: Automation Uploader |
| 4 | + |
| 5 | +# Controls when the workflow will run |
| 6 | +on: |
| 7 | + # Triggers the workflow on push or pull request events but only for the "main" branch |
| 8 | + push: |
| 9 | + branches: [ "main" ] |
| 10 | + |
| 11 | + # Allows you to run this workflow manually from the Actions tab |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 15 | +jobs: |
| 16 | + # This workflow contains a single job called "build" |
| 17 | + build: |
| 18 | + # The type of runner that the job will run on |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + |
| 23 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 24 | + steps: |
| 25 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Retrieve Required Data |
| 29 | + id: extract-name |
| 30 | + run: | |
| 31 | + MESSAGE=$(yq '.message' metadata.yml) |
| 32 | + VERSION=$(yq -r '.version' metadata.yml) |
| 33 | + NAME=$(yq '.name' metadata.yml) |
| 34 | + STATUS=$(yq '.status' metadata.yml) |
| 35 | + echo "$MESSAGE" > message.txt |
| 36 | + echo "MESSAGE<<EOF" >> $GITHUB_ENV |
| 37 | + cat message.txt >> $GITHUB_ENV |
| 38 | + echo "EOF" >> $GITHUB_ENV |
| 39 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 40 | + echo "FILE_NAME=$NAME-$VERSION \($STATUS\).mcpack" >> $GITHUB_ENV |
| 41 | + echo "NAME=$NAME" >> $GITHUB_ENV |
| 42 | +
|
| 43 | + - name: Compression Session |
| 44 | + run: | |
| 45 | + zip -r temp.zip BP/* |
| 46 | + mv temp.zip "$FILE_NAME" |
| 47 | +
|
| 48 | + - name: Upload to Github Tag |
| 49 | + run: | |
| 50 | + git config user.name "github-actions[bot]" |
| 51 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 52 | + git tag -a $VERSION -m "$MESSAGE" |
| 53 | + git push origin $VERSION |
| 54 | +
|
| 55 | + - name: Create Release |
| 56 | + id: create_release |
| 57 | + uses: actions/create-release@v1 |
| 58 | + with: |
| 59 | + tag_name: ${{ env.VERSION }} |
| 60 | + release_name: ${{ env.VERSION }} |
| 61 | + body: | |
| 62 | + ${{ env.MESSAGE }} |
| 63 | + draft: false |
| 64 | + prerelease: false |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Upload MCPACK file |
| 69 | + uses: actions/upload-release-asset@v1 |
| 70 | + with: |
| 71 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 72 | + asset_path: ./${{ env.FILE_NAME }} |
| 73 | + asset_name: ${{ env.FILE_NAME }} |
| 74 | + asset_content_type: application/octet-stream |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: Upload to CurseForge |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + CF_API_TOKEN: "${{ secrets.CURSEFORGE_TOKEN }}" |
| 82 | + FILE_NAME: ${{ env.FILE_NAME }} |
| 83 | + MESSAGE: ${{ env.MESSAGE }} |
| 84 | + run: | |
| 85 | + echo @$FILE_NAME |
| 86 | + RESPONSE=$(curl -X POST \ |
| 87 | + -H "X-Api-Token: $CF_API_TOKEN" \ |
| 88 | + -F metadata="$(jq -n --arg changelog "${{ env.MESSAGE }}" \ |
| 89 | + '{"changelog": "${{ env.MESSAGE }}", "changelogType": "markdown", "gameVersion": [13429, 13543, 13604], "releaseType": "release"}')" \ |
| 90 | + -F "file=@\"./$FILE_NAME\"" \ |
| 91 | + "https://minecraft-bedrock.curseforge.com/api/projects/1268971/upload-file") |
| 92 | + FILE_ID=$(echo $RESPONSE | jq -r '.id') |
| 93 | + echo "CURSEFORGE_FILE_ID=$FILE_ID" >> $GITHUB_ENV |
| 94 | + |
| 95 | + - name: Notify Discord |
| 96 | + env: |
| 97 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} |
| 98 | + NAME: Changes Logger |
| 99 | + MESSAGE: ${{ env.MESSAGE }} |
| 100 | + CF_FILE_ID: ${{ env.CURSEFORGE_FILE_ID }} |
| 101 | + AVATAR: https://cdn.discordapp.com/attachments/1388361920696029265/1393812849880469595/Change_Logger.png?ex=687488df&is=6873375f&hm=8e241886a7643c7928c7d02bf93aec07343e233d19f141cb20b5f051fc2285c5& |
| 102 | + run: | |
| 103 | + FULL_MESSAGE="$MESSAGE" |
| 104 | + USERNAME="$NAME" |
| 105 | + AVATAR_URL="$AVATAR" |
| 106 | + JSON=$(jq -nc --arg content "$FULL_MESSAGE |
| 107 | + |
| 108 | + ### Download Section |
| 109 | + - <:Github:1393587335979073698> [Github](<${{ steps.create_release.outputs.html_url }}>) |
| 110 | + - <:CurseForge:1377993483800940584> [CurseForge](<https://www.curseforge.com/minecraft-bedrock/scripts/spawn-randomizer/files/$CF_FILE_ID>) |
| 111 | + <@&1373921268687966208> |
| 112 | + -# You may need to wait for CurseForge to upload the file in order for you to download it. Therefore, you can either wait for the file in curseforge or download it directly from Github." --arg name "$USERNAME" --arg avatar "$AVATAR_URL" '{content: $content, username: $name, avatar_url: $avatar}') |
| 113 | + curl -X POST -H "Content-Type: application/json" -d "$JSON" "$DISCORD_WEBHOOK" |
0 commit comments