name: "Build RetroDECK" on: push: branches: - main - cooker* - feat* - branch/cooker* paths: - '.github/workflows/**' - 'automation_tools/**' - 'config/**' - 'functions/**' - 'rd-submodules/**' - '*.sh' - 'net.retrodeck.retrodeck.yml' - 'net.retrodeck.retrodeck.appdata.xml' pull_request: branches: - main - cooker* workflow_dispatch: permissions: contents: write jobs: # Build RetroDECK Job Build_RetroDECK: runs-on: retrodeck-server outputs: tag: ${{ steps.version-tag.outputs.tag }} release_body: ${{ steps.version-tag.outputs.release_body }} env: REKKU_TOKEN: ${{ needs.Generate-Rekku-Token.outputs.rekku_token }} steps: # Remove Stuck Mounts - name: Remove stuck mounts run: | sudo umount -f /home/ubuntu/actions-runner/_work/RetroDECK/RetroDECK/.flatpak-builder/rofiles/* sudo umount -f $HOME/actions-run/_work/RetroDECK/RetroDECK/.flatpak-builder/rofiles/* continue-on-error: true # Clone Repository - name: Clone RetroDECK repo uses: actions/checkout@v4 with: submodules: true # Install Dependencies - name: Install dependencies run: curl "https://raw.githubusercontent.com/RetroDECK/components-template/main/automation_tools/install_dependencies.sh" | bash # Generate Build ID for Cooker Branches - name: Generate cooker build ID if: github.ref != 'refs/heads/main' run: "/bin/bash ${GITHUB_WORKSPACE}/automation_tools/cooker_build_id.sh" # Generates a version tag based on the event type (main branch, PR, or cooker) and sets it as output. - name: Generate Version Tag id: version-tag run: | # Source the version extractor script and fetch the manifest version source automation_tools/version_extractor.sh MANIFEST_VERSION="$(fetch_manifest_version)" # Ensure the manifest version was successfully extracted if [[ -z "$MANIFEST_VERSION" ]]; then echo "[ERROR] Failed to extract the manifest version." exit 1 fi # Determine the tag based on the GitHub event context if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then # Main branch tag TAG="$MANIFEST_VERSION" MAKE_LATEST=true elif [[ "$GITHUB_EVENT_NAME" == "pull_request" || "$GITHUB_EVENT_NAME" == "pull_request_target" ]]; then # Pull request tag, sanitize the source branch source_branch="${GITHUB_HEAD_REF//\//-}" TAG="PR-$source_branch-${{ github.run_id }}" MAKE_LATEST=false else # Other branches (cooker branches) TAG="$MANIFEST_VERSION-${{ env.BUILD_ID }}" MAKE_LATEST=true fi # Export the tag and make_latest values echo "tag=$TAG" >> $GITHUB_OUTPUT echo "make_latest=$MAKE_LATEST" >> $GITHUB_OUTPUT # Debug output echo "[INFO] MANIFEST_VERSION: $MANIFEST_VERSION" echo "[INFO] Generated TAG: $TAG" echo "[INFO] MAKE_LATEST: $MAKE_LATEST" # backing up manifest in case download fails and hashes must be recalculated - name: Manifest backup run: "cp ${GITHUB_WORKSPACE}/net.retrodeck.retrodeck.yml ${GITHUB_WORKSPACE}/net.retrodeck.retrodeck.yml.bak" - name: Run pre-build automation tasks run: "/bin/bash ${GITHUB_WORKSPACE}/automation_tools/pre_build_automation.sh" - name: "Adding flatpak portal for automated updates (Cooker only)" if: github.ref != 'refs/heads/main' run: "/bin/bash ${GITHUB_WORKSPACE}/automation_tools/cooker_flatpak_portal_add.sh" - name: "Updating release notes in appdata" run: "automation_tools/appdata_management.sh" - name: "[DEBUG] Outputting manifest" run: cat net.retrodeck.retrodeck.yml # Get Commits Since Last Release - name: Get commits since last release id: get-commits run: | LATEST_TAG=$(git describe --tags --abbrev=0 $(git rev-list --tags --max-count=1 --first-parent) || echo "") if [ -z "$LATEST_TAG" ]; then COMMITS=$(git log HEAD --pretty=format:"- %s") else COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"- %s") fi echo "commits=$COMMITS" >> $GITHUB_OUTPUT # Generate Release Body - name: Generate release body text id: generate-body run: | # Initialize the release body RELEASE_BODY="# Release Notes\n" RELEASE_BODY+="This release is based on the commit: RetroDECK/RetroDECK@c8bd579ad4d0922ba7ab1f5c122cc782ff6adc66.\n" RELEASE_BODY+="On branch [cooker](https://github.com/RetroDECK/RetroDECK/tree/cooker).\n\n" RELEASE_BODY+="## Commits since last release\n" RELEASE_BODY+="- RELEASE NOTES: fixed body\n\n" # Define the XML file path xml_file="./net.retrodeck.retrodeck.appdata.xml" # Check if the XML file exists if [[ ! -f "$xml_file" ]]; then echo "Error: XML file not found: $xml_file" exit 1 fi # Extract the raw description content using xmlstarlet raw_description=$(xmlstarlet sel -t -m "/component/releases/release[1]/description/*" -c "." -n "$xml_file" 2>/dev/null) # Check if xmlstarlet extraction was successful if [[ $? -ne 0 ]]; then echo "Error: Failed to extract description content using xmlstarlet" exit 1 fi # Convert

tags to markdown headers using sed markdown_description=$(echo "$raw_description" | sed -e 's|

|\n### |g' -e 's|

||g') # Convert
  • tags to bullet points and trim spaces markdown_description=$(echo "$markdown_description" | sed -e 's|||g' -e 's|
  • |- |g' -e 's|
  • ||g' | awk '{$1=$1;print}') # Remove any remaining XML tags markdown_description=$(echo "$markdown_description" | sed -e 's/<[^>]*>//g') # Debug: Print the markdown description echo "Markdown Description:" echo "$markdown_description" # Append markdown content to the release body RELEASE_BODY+="$markdown_description" # Set the release body as an output using heredoc to preserve newlines echo "release_body<> $GITHUB_OUTPUT echo -e "$RELEASE_BODY" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - name: "Build flatpak: download only" run: "/bin/bash ${GITHUB_WORKSPACE}/automation_tools/flatpak_build_download_only.sh" # Sometimes flatpak download fails, in this case it tries a second time - name: "Build flatpak: download only (retry)" if: steps.flatpak-download.outcome == 'failure' run: | echo "Download failed, maybe some hash changed since the build start." echo "Recalculating hashes and retrying download..." rm -f "{GITHUB_WORKSPACE}/net.retrodeck.retrodeck.yml" cp "${GITHUB_WORKSPACE}/net.retrodeck.retrodeck.yml.bak" "${GITHUB_WORKSPACE}/net.retrodeck.retrodeck.yml" "${GITHUB_WORKSPACE}/automation_tools/pre_build_automation.sh" "${GITHUB_WORKSPACE}/automation_tools/flatpak_build_download_only.sh" - name: Build flatpak run: "/bin/bash ${GITHUB_WORKSPACE}/automation_tools/flatpak_build_only.sh" - name: Create Bundle run: "/bin/bash ${GITHUB_WORKSPACE}/automation_tools/flatpak_build_bundle.sh" # Upload artifacts for other jobs - name: Upload Build Artifacts uses: actions/upload-artifact@v4 with: name: retrodeck-artifacts path: | RetroDECK*.flatpak RetroDECK*.flatpak.sha RetroDECK*Artifact.tar.gz GitHub-publish: runs-on: ubuntu-latest needs: Build_RetroDECK env: tag: ${{ needs.Build_RetroDECK.outputs.tag }} release_body: ${{ needs.Build_RetroDECK.outputs.release_body }} MAKE_LATEST: ${{ needs.Build_RetroDECK.outputs.MAKE_LATEST }} steps: - name: Generate a token for Rekku if: ${{ github.repository == 'RetroDECK/RetroDECK' }} id: generate-rekku-token uses: actions/create-github-app-token@v1 with: app-id: ${{ vars.REKKU_APP_ID }} private-key: ${{ secrets.REKKU_PRIVATE_KEY }} repositories: "RetroDECK,Cooker" owner: "RetroDECK" # Determine if Target Repository is Main or not, in that case is a Cooker build - name: Determine target repository id: set-repo run: | if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then echo "repo_name=RetroDECK" >> $GITHUB_ENV else echo "repo_name=Cooker" >> $GITHUB_ENV fi # Publish Release - name: Publish release uses: ncipollo/release-action@v1 with: tag: ${{ env.tag }} name: "RetroDECK ${{ env.tag }}" body: ${{ env.release_body }} artifacts: "*.flatpak,*.flatpak.sha,*Artifact.tar.gz" allowUpdates: true makeLatest: ${{ env.MAKE_LATEST }} token: ${{ steps.generate-rekku-token.outputs.token }} repo: "${{ env.repo_name }}" continue-on-error: ${{ github.ref != 'refs/heads/main' }} # Rewrite Tag (for Main Branch Only) - name: Rewrite Tag if: github.ref == 'refs/heads/main' run: | git submodule deinit -f --all git fetch --tags if git rev-parse --verify "${{ steps.version-tag.outputs.tag }}" >/dev/null 2>&1; then git tag -d "${{ steps.version-tag.outputs.tag }}" git push --delete origin "${{ steps.version-tag.outputs.tag }}" fi git tag "${{ steps.version-tag.outputs.tag }}" git push origin "${{ steps.version-tag.outputs.tag }}" env: GITHUB_TOKEN: ${{ steps.generate-rekku-token.outputs.token }} # As backup we're even publishing the build on our own selfhosted Fogejo instance # Forgejo Publish Job if main branch # Forgejo-publish: # if: github.ref == 'refs/heads/main' # needs: Build_RetroDECK # uses: RetroDECK/components-template/.github/workflows/fogejo_publish_release.yml@main # with: # release_body: ${{ needs.Build_RetroDECK.outputs.release_body }} # artifacts: "*.flatpak,*.flatpak.sha,*Artifact.tar.gz" # tag: ${{ needs.Build_RetroDECK.outputs.tag }} # secrets: # FORGEJO_TRIGGER_BUILD_TOKEN: ${{ secrets.FORGEJO_TRIGGER_BUILD_TOKEN }}