|
| 1 | +name: Build Project-Athena |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches-ignore: [translation] |
| 6 | + paths-ignore: |
| 7 | + - 'README.md' |
| 8 | + pull_request: |
| 9 | + branches: ["*"] |
| 10 | + paths-ignore: |
| 11 | + - 'README.md' |
| 12 | + release: |
| 13 | + types: [published] |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: ci-${{ startsWith(github.ref, 'refs/pull') && github.ref || 'publish' }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + container: devkitpro/devkitarm |
| 23 | + name: Build with Docker using devkitARM |
| 24 | + outputs: |
| 25 | + commit_tag: ${{ steps.build.outputs.commit_tag }} |
| 26 | + commit_hash: ${{ steps.build.outputs.commit_hash }} |
| 27 | + author_name: ${{ steps.build.outputs.author_name }} |
| 28 | + committer_name: ${{ steps.build.outputs.committer_name }} |
| 29 | + commit_subject: ${{ steps.build.outputs.commit_subject }} |
| 30 | + commit_message: ${{ steps.build.outputs.commit_message }} |
| 31 | + steps: |
| 32 | + - name: Checkout repo |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + submodules: recursive |
| 36 | + fetch-depth: 0 |
| 37 | + - name: Setup environment |
| 38 | + run: git config --global safe.directory '*' |
| 39 | + - name: Install tools |
| 40 | + run: | |
| 41 | + sudo apt-get update |
| 42 | + sudo apt-get install p7zip-full -y |
| 43 | +
|
| 44 | + curl -L https://github.com/Epicpkmn11/bannertool/releases/latest/download/bannertool.zip -o bannertool.zip |
| 45 | + sudo 7z e bannertool.zip linux-x86_64/bannertool |
| 46 | + sudo chmod +x bannertool |
| 47 | + mv bannertool /usr/local/bin |
| 48 | + rm bannertool.zip |
| 49 | + curl -L https://github.com/3DSGuy/Project_CTR/releases/download/makerom-v0.17/makerom-v0.17-ubuntu_x86_64.zip -o makerom-v0.17-ubuntu_x86_64.zip |
| 50 | + sudo 7z e makerom-v0.17-ubuntu_x86_64.zip |
| 51 | + sudo chmod +x makerom |
| 52 | + mv makerom /usr/local/bin |
| 53 | + rm makerom-v0.17-ubuntu_x86_64.zip |
| 54 | + - name: Build |
| 55 | + id: build |
| 56 | + run: | |
| 57 | + make |
| 58 | + mkdir -p ~/artifacts |
| 59 | + cp Project-Athena.3dsx ~/artifacts |
| 60 | + cp Project-Athena.cia ~/artifacts |
| 61 | + echo ::set-output name=commit_tag::$(git describe --abbrev=0 --tags --exclude git) |
| 62 | + echo ::set-output name=commit_hash::$(git log --format=%h -1) |
| 63 | +
|
| 64 | + # Webhook info |
| 65 | + echo "::set-output name=author_name::$(git log -1 $GITHUB_SHA --pretty=%aN)" |
| 66 | + echo "::set-output name=committer_name::$(git log -1 $GITHUB_SHA --pretty=%cN)" |
| 67 | + echo "::set-output name=commit_subject::$(git log -1 $GITHUB_SHA --pretty=%s)" |
| 68 | + echo "::set-output name=commit_message::$(git log -1 $GITHUB_SHA --pretty=%b)" |
| 69 | + - name: Publish build to GH Actions |
| 70 | + uses: actions/upload-artifact@v4 |
| 71 | + with: |
| 72 | + path: ~/artifacts/* |
| 73 | + name: build |
| 74 | + |
| 75 | + # Only run this for non-PR jobs. |
| 76 | + publish_build: |
| 77 | + runs-on: ubuntu-latest |
| 78 | + name: Publish build |
| 79 | + if: ${{ success() && !startsWith(github.ref, 'refs/pull') }} |
| 80 | + needs: build |
| 81 | + env: |
| 82 | + COMMIT_TAG: ${{ needs.build.outputs.commit_tag }} |
| 83 | + COMMIT_HASH: ${{ needs.build.outputs.commit_hash }} |
| 84 | + AUTHOR_NAME: ${{ needs.build.outputs.author_name }} |
| 85 | + COMMIT_SUBJECT: ${{ needs.build.outputs.commit_subject }} |
| 86 | + COMMIT_MESSAGE: ${{ needs.build.outputs.commit_message }} |
| 87 | + steps: |
| 88 | + - name: Download artifacts |
| 89 | + uses: actions/download-artifact@v4 |
| 90 | + with: |
| 91 | + name: build |
| 92 | + path: build |
| 93 | + # This one always runs |
| 94 | + - name: Delete the 'git' release |
| 95 | + run: | |
| 96 | + # Get the release ID for tag 'git' |
| 97 | + AUTH_HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}" |
| 98 | + CONTENT_TYPE="Content-Type: application/json" |
| 99 | + API_URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/git" |
| 100 | +
|
| 101 | + RESPONSE=$(curl -H "$AUTH_HEADER" -H "$CONTENT_TYPE" "$API_URL") |
| 102 | + STATUS=$(echo $RESPONSE | jq -r .status) |
| 103 | + if [ "$STATUS" != "404" ]; then |
| 104 | + # If it exists, delete it |
| 105 | + ID=$(echo $RESPONSE | jq -r .id) |
| 106 | + API_URL="https://api.github.com/repos/${{ github.repository }}/releases/$ID" |
| 107 | + curl -XDELETE -H "$AUTH_HEADER" -H "$CONTENT_TYPE" "$API_URL" |
| 108 | + fi |
| 109 | +
|
| 110 | + # This one only runs for releases |
| 111 | + - name: Upload to ${{ github.ref_name }} release |
| 112 | + if: ${{ startsWith(github.ref, 'refs/tags') }} |
| 113 | + run: | |
| 114 | + ID=$(jq -r '.release.id' $GITHUB_EVENT_PATH) |
| 115 | +
|
| 116 | + for file in ${{ github.workspace }}/build/*; do |
| 117 | + AUTH_HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}" |
| 118 | + CONTENT_LENGTH="Content-Length: $(stat -c%s $file)" |
| 119 | + CONTENT_TYPE="Content-Type: application/7z-x-compressed" |
| 120 | + UPLOAD_URL="https://uploads.github.com/repos/${{ github.repository }}/releases/$ID/assets?name=$(basename $file)" |
| 121 | +
|
| 122 | + curl -XPOST -H "$AUTH_HEADER" -H "$CONTENT_LENGTH" -H "$CONTENT_TYPE" --upload-file "$file" "$UPLOAD_URL" |
| 123 | + done |
| 124 | + |
| 125 | + # This one only runs if it's not a release run |
| 126 | + - name: Upload to 'git' release |
| 127 | + if: ${{ !startsWith(github.ref, 'refs/tags') }} |
| 128 | + run: | |
| 129 | + AUTH_HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}" |
| 130 | + CONTENT_TYPE="Content-Type: application/json" |
| 131 | + API_URL="https://api.github.com/repos/${{ github.repository }}/releases" |
| 132 | + RELEASE_INFO="{\"tag_name\": \"git\", \"name\": \"Continuous Build - $COMMIT_HASH\", \"body\": \"$AUTHOR_NAME - $COMMIT_SUBJECT\n\n$COMMIT_MESSAGE\", \"prerelease\": true}" |
| 133 | +
|
| 134 | + RESPONSE=$(curl -XPOST -H "$AUTH_HEADER" -H "$CONTENT_TYPE" "$API_URL" -d "$RELEASE_INFO") |
| 135 | + ID=$(echo $RESPONSE | jq -r '.id') |
| 136 | +
|
| 137 | + for file in ${{ github.workspace }}/build/*; do |
| 138 | + CONTENT_LENGTH="Content-Length: $(stat -c%s $file)" |
| 139 | + CONTENT_TYPE="Content-Type: application/7z-x-compressed" |
| 140 | + UPLOAD_URL="https://uploads.github.com/repos/${{ github.repository }}/releases/$ID/assets?name=$(basename $file)" |
| 141 | +
|
| 142 | + curl -XPOST -H "$AUTH_HEADER" -H "$CONTENT_LENGTH" -H "$CONTENT_TYPE" --upload-file "$file" "$UPLOAD_URL" |
| 143 | + done |
| 144 | +
|
| 145 | + send_success_webhook: |
| 146 | + runs-on: ubuntu-latest |
| 147 | + needs: [publish_build, build] |
| 148 | + name: Send success webhook |
| 149 | + if: ${{ !startsWith(github.ref, 'refs/pull') && success() }} |
| 150 | + env: |
| 151 | + COMMIT_HASH: ${{ needs.build.outputs.commit_hash }} |
| 152 | + AUTHOR_NAME: ${{ needs.build.outputs.author_name }} |
| 153 | + COMMITTER_NAME: ${{ needs.build.outputs.committer_name }} |
| 154 | + COMMIT_SUBJECT: ${{ needs.build.outputs.commit_subject }} |
| 155 | + COMMIT_MESSAGE: ${{ needs.build.outputs.commit_message }} |
| 156 | + steps: |
| 157 | + - name: Send success webhook |
| 158 | + run: | |
| 159 | + curl -o send.sh https://raw.githubusercontent.com/Universal-Team/discord-webhooks/master/send-ghactions.sh |
| 160 | + chmod +x send.sh |
| 161 | + ./send.sh success ${{ secrets.WEBHOOK_URL }} |
| 162 | + send_failure_webhook: |
| 163 | + runs-on: ubuntu-latest |
| 164 | + needs: [publish_build, build] |
| 165 | + name: Send failure webhook |
| 166 | + if: ${{ !startsWith(github.ref, 'refs/pull') && failure() }} |
| 167 | + steps: |
| 168 | + - name: Send failure webhook |
| 169 | + run: | |
| 170 | + curl -o send.sh https://raw.githubusercontent.com/Universal-Team/discord-webhooks/master/send-ghactions.sh |
| 171 | + chmod +x send.sh |
| 172 | + ./send.sh failure ${{ secrets.WEBHOOK_URL }} |
0 commit comments