From 0ffb96fb1d244a56e95ddaebd93ec5a18d1fe25e Mon Sep 17 00:00:00 2001 From: Harmony <19539165+BitsOfAByte@users.noreply.github.com> Date: Sat, 14 Jan 2023 19:38:31 +0000 Subject: [PATCH 1/6] Update workflow --- .github/workflows/make-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml index 3e90ab45..5ccf0f00 100644 --- a/.github/workflows/make-release.yml +++ b/.github/workflows/make-release.yml @@ -3,7 +3,7 @@ name: "PR XLCore to Flatpak" on: push: tags: - - "v*" + - "*.*.*" jobs: Release: @@ -73,7 +73,7 @@ jobs: cd /tmp/xlcore-flatpak python3 -m pip install pyyaml - python3 update_flatpak_manifest.py dev.goats.xivlauncher.yml $(echo ${{ github.ref_name }} | sed -e "s/^v//g") ${{ github.sha }} + python3 update_flatpak_manifest.py dev.goats.xivlauncher.yml dev.goats.xivlauncher.appdata.xml $(echo ${{ github.ref_name }} | sed -e "s/^v//g") ${{ github.sha }} rm update_flatpak_manifest.py git checkout -b xlcore-${{ github.ref_name }} From 4f75cacb2daa25d4e1c99cae9a04688c7affd90e Mon Sep 17 00:00:00 2001 From: Harmony <19539165+BitsOfAByte@users.noreply.github.com> Date: Sat, 14 Jan 2023 19:38:56 +0000 Subject: [PATCH 2/6] Update script --- .github/scripts/update_flatpak_manifest.py | 52 +++++++++++++++------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/.github/scripts/update_flatpak_manifest.py b/.github/scripts/update_flatpak_manifest.py index 12580004..587f7176 100644 --- a/.github/scripts/update_flatpak_manifest.py +++ b/.github/scripts/update_flatpak_manifest.py @@ -1,34 +1,54 @@ import yaml import sys +import xml.etree.ElementTree as ET +from datetime import date -if len(sys.argv) != 4: - print(f'Usage: python3 {sys.argv[0]} ') +if len(sys.argv) != 5: + print(f'Usage: python3 {sys.argv[0]} ') sys.exit(1) -fileName = sys.argv[1] -newTag = sys.argv[2] -newCommit = sys.argv[3] +manifestFile = sys.argv[1] +appstreamFile = sys.argv[2] +newTag = sys.argv[3] +newCommit = sys.argv[4] -# Read the given file and try to parse it to update its tag and commit. -with open(fileName, 'r') as f: - config = yaml.safe_load(f) - success = False +# Read the manifest file and update the tag and commit +with open(manifestFile, 'r') as f: + yamlFile = yaml.safe_load(f) + manifestUpdateSuccess = False try: - for module in config['modules']: + for module in yamlFile['modules']: if module['name'] == 'xivlauncher': for source in module['sources']: if source['url'] == 'https://github.com/goatcorp/XIVLauncher.Core.git': source['tag'] = newTag source['commit'] = newCommit - with open(fileName, 'w') as f: - yaml.dump(config, f) - success = True + with open(manifestFile, 'w') as f: + yaml.dump(yamlFile, f) + manifestUpdateSuccess = True break; except KeyError: pass - if success is False: - print('Error: failed to update XIVLauncher.Core commit and tag.. exiting') + if manifestUpdateSuccess is False: + print('Error: failed to update XIVLauncher.Core manifest.. exiting') sys.exit(1) - print(f'Updated XIVLauncher.Core tag to {newTag} and commit to {newCommit} in {fileName}') +# Read the appstream file and update the tag and commit +with open(appstreamFile, 'r') as f: + tree = ET.parse(f) + root = tree.getroot() + appstreamUpdateSuccess = False + for component in root: + if component.tag == 'releases': + for release in component: + release.set('date', date.today().strftime("%Y-%m-%d")) + release.set('version', newTag) + tree.write(appstreamFile) + appstreamUpdateSuccess = True + break + if appstreamUpdateSuccess is False: + print('Error: failed to update appstream file.. exiting') + sys.exit(1) + +print(f'Updated {manifestFile} and {appstreamFile} to tag {newTag} and commit {newCommit} on {date.today().strftime("%Y-%m-%d")}') From 281bb51d8b905f06f98bf75c5a57dfc85bedea7b Mon Sep 17 00:00:00 2001 From: Harmony <19539165+BitsOfAByte@users.noreply.github.com> Date: Sat, 14 Jan 2023 20:57:57 +0000 Subject: [PATCH 3/6] Add artifacts to tag releases --- .github/workflows/make-release.yml | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml index 5ccf0f00..9a439bc3 100644 --- a/.github/workflows/make-release.yml +++ b/.github/workflows/make-release.yml @@ -5,6 +5,9 @@ on: tags: - "*.*.*" +permissions: + contents: write + jobs: Release: runs-on: ubuntu-latest @@ -33,9 +36,17 @@ jobs: working-directory: ./src/XIVLauncher.Core/ run: dotnet restore - - name: Dotnet Build + - name: Dotnet Build (Default) + working-directory: ./src/XIVLauncher.Core/ + run: dotnet build --configuration Release --no-restore -o ./dist/XIVLauncher.Core + + - name: Dotnet Build (Arch) + working-directory: ./src/XIVLauncher.Core/ + run: dotnet build --configuration Release -p:DefineConstants=WINE_XIV_ARCH_LINUX --no-restore -o ./dist/XIVLauncher.Core-arch + + - name: Dotnet Build (Fedora) working-directory: ./src/XIVLauncher.Core/ - run: dotnet build --configuration Release --no-restore + run: dotnet build --configuration Release -p:DefineConstants=WINE_XIV_FEDORA_LINUX --no-restore -o ./dist/XIVLauncher.Core-fedora - name: Setup Python3 uses: actions/setup-python@v4 @@ -82,8 +93,20 @@ jobs: git push --set-upstream origin xlcore-${{ github.ref_name }} gh pr create -t "Update XIVLauncher.Core to ${{ github.ref_name }}" -b "This is an automated pull request" -B master - + + - name: Zip Release + run: | + sudo apt install zip -y + mkdir -p ./dist + zip -r ./dist/XIVLauncher.Core.zip ./src/XIVLauncher.Core/dist/XIVLauncher.Core/ + zip -r ./dist/XIVLauncher.Core-arch.zip ./src/XIVLauncher.Core/dist/XIVLauncher.Core-arch/ + zip -r ./dist/XIVLauncher.Core-fedora.zip ./src/XIVLauncher.Core/dist/XIVLauncher.Core-fedora/ + - name: Release on GitHub uses: softprops/action-gh-release@v1 with: generate_release_notes: true + files: | + ./dist/XIVLauncher.Core.zip + ./dist/XIVLauncher.Core-arch.zip + ./dist/XIVLauncher.Core-fedora.zip From 94e041e6f57b3d2e40a9fd6e6ecbbf051521796a Mon Sep 17 00:00:00 2001 From: Harmony <19539165+BitsOfAByte@users.noreply.github.com> Date: Sat, 14 Jan 2023 20:58:34 +0000 Subject: [PATCH 4/6] Update build artifact generation for builds --- .github/workflows/build.yml | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 94e6b889..d8ca67ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,36 +31,30 @@ jobs: - name: Dotnet Build (Default) working-directory: ./src/XIVLauncher.Core/ - run: | - rm -rf bin - dotnet build --configuration Release --no-restore + run: dotnet build --configuration Release --no-restore -o ./dist/XIVLauncher.Core - - name: Upload Artifact (Default) + - name: Dotnet Build (Arch) + working-directory: ./src/XIVLauncher.Core/ + run: dotnet build --configuration Release -p:DefineConstants=WINE_XIV_ARCH_LINUX --no-restore -o ./dist/XIVLauncher.Core-arch + + - name: Dotnet Build (Fedora) + working-directory: ./src/XIVLauncher.Core/ + run: dotnet build --configuration Release -p:DefineConstants=WINE_XIV_FEDORA_LINUX --no-restore -o ./dist/XIVLauncher.Core-fedora + + - name: Upload Artifacts (Default) uses: actions/upload-artifact@v3 with: - name: XIVLauncher.Core-default - path: ./src/XIVLauncher.Core/bin/ + name: XIVLauncher.Core + path: ./src/XIVLauncher.Core/dist/XIVLauncher.Core - - name: Dotnet Build (Arch) - working-directory: ./src/XIVLauncher.Core/ - run: | - rm -rf bin - dotnet build --configuration Release -p:DefineConstants=WINE_XIV_ARCH_LINUX --no-restore - - name: Upload Artifacts (Arch) uses: actions/upload-artifact@v3 with: name: XIVLauncher.Core-arch - path: ./src/XIVLauncher.Core/bin/ - - - name: Dotnet Build (Fedora) - working-directory: ./src/XIVLauncher.Core/ - run: | - rm -rf bin - dotnet build --configuration Release -p:DefineConstants=WINE_XIV_FEDORA_LINUX --no-restore + path: ./src/XIVLauncher.Core/dist/XIVLauncher.Core-arch - name: Upload Artifacts (Fedora) uses: actions/upload-artifact@v3 with: name: XIVLauncher.Core-fedora - path: ./src/XIVLauncher.Core/bin/ + path: ./src/XIVLauncher.Core/dist/XIVLauncher.Core-fedora From e1812f6620ef38d9914a8978dcaaec54c8c045a2 Mon Sep 17 00:00:00 2001 From: Harmony <19539165+BitsOfAByte@users.noreply.github.com> Date: Sat, 25 Mar 2023 14:45:31 +0000 Subject: [PATCH 5/6] Cleanup and fix nuget dep generation --- .github/workflows/make-release.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml index 9a439bc3..f852141e 100644 --- a/.github/workflows/make-release.yml +++ b/.github/workflows/make-release.yml @@ -1,4 +1,4 @@ -name: "PR XLCore to Flatpak" +name: "Release XLCore" on: push: @@ -30,7 +30,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 6.0.x # Set this to be the same as the projects required dotnet version. - name: Dotnet Restore working-directory: ./src/XIVLauncher.Core/ @@ -58,8 +58,8 @@ jobs: sudo apt update -y sudo apt install flatpak -y flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo - flatpak install --user org.freedesktop.Sdk.Extension.dotnet6/x86_64/21.08 -y - flatpak install --user org.freedesktop.Sdk/x86_64/21.08 -y + flatpak install --user org.freedesktop.Sdk.Extension.dotnet6/x86_64/22.08 -y # Update this when needed. + flatpak install --user org.freedesktop.Sdk/x86_64/22.08 -y # As well as this, if dependency generation is failing. - name: Generate nuget-dependencies.json working-directory: ./src/XIVLauncher.Core/ @@ -106,6 +106,8 @@ jobs: uses: softprops/action-gh-release@v1 with: generate_release_notes: true + #body_path: .github/release_notices.md # If you want to add notes to the top of all releases, uncomment this + append_body: true # and this to make sure they are appended, not replacing the original. files: | ./dist/XIVLauncher.Core.zip ./dist/XIVLauncher.Core-arch.zip From 7e8bee3d465222606aed1307bfe15a11afcae94c Mon Sep 17 00:00:00 2001 From: Harmony Date: Sat, 17 Jun 2023 13:48:30 +0100 Subject: [PATCH 6/6] ci: Improve all flows --- .github/scripts/update_flatpak_manifest.py | 1 + .github/workflows/build.yml | 26 ++----- .github/workflows/make-release.yml | 88 ++++++++++++++-------- 3 files changed, 62 insertions(+), 53 deletions(-) diff --git a/.github/scripts/update_flatpak_manifest.py b/.github/scripts/update_flatpak_manifest.py index 587f7176..eb0aedf6 100644 --- a/.github/scripts/update_flatpak_manifest.py +++ b/.github/scripts/update_flatpak_manifest.py @@ -3,6 +3,7 @@ import xml.etree.ElementTree as ET from datetime import date +print("Ran with args: " + str(sys.argv)) if len(sys.argv) != 5: print(f'Usage: python3 {sys.argv[0]} ') sys.exit(1) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d8ca67ee..dc025a85 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,9 @@ on: jobs: Build: runs-on: ubuntu-latest + defaults: + run: + working-directory: ./src/XIVLauncher.Core/ concurrency: group: ${{ github.head_ref }}" cancel-in-progress: true @@ -26,35 +29,16 @@ jobs: dotnet-version: 6.0.x - name: Dotnet Restore - working-directory: ./src/XIVLauncher.Core/ run: dotnet restore - name: Dotnet Build (Default) - working-directory: ./src/XIVLauncher.Core/ run: dotnet build --configuration Release --no-restore -o ./dist/XIVLauncher.Core - name: Dotnet Build (Arch) - working-directory: ./src/XIVLauncher.Core/ run: dotnet build --configuration Release -p:DefineConstants=WINE_XIV_ARCH_LINUX --no-restore -o ./dist/XIVLauncher.Core-arch - name: Dotnet Build (Fedora) - working-directory: ./src/XIVLauncher.Core/ run: dotnet build --configuration Release -p:DefineConstants=WINE_XIV_FEDORA_LINUX --no-restore -o ./dist/XIVLauncher.Core-fedora - - name: Upload Artifacts (Default) - uses: actions/upload-artifact@v3 - with: - name: XIVLauncher.Core - path: ./src/XIVLauncher.Core/dist/XIVLauncher.Core - - - name: Upload Artifacts (Arch) - uses: actions/upload-artifact@v3 - with: - name: XIVLauncher.Core-arch - path: ./src/XIVLauncher.Core/dist/XIVLauncher.Core-arch - - - name: Upload Artifacts (Fedora) - uses: actions/upload-artifact@v3 - with: - name: XIVLauncher.Core-fedora - path: ./src/XIVLauncher.Core/dist/XIVLauncher.Core-fedora + - name: Dotnet Test + run: dotnet test --no-build --verbosity normal \ No newline at end of file diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml index f852141e..fcee5e5b 100644 --- a/.github/workflows/make-release.yml +++ b/.github/workflows/make-release.yml @@ -12,8 +12,14 @@ jobs: Release: runs-on: ubuntu-latest env: + # These are the user credentials that will be used to make the PR. COMMIT_USER: github-actions[bot] COMMIT_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com + # Where the changes will be made. + HEAD_BRANCH: xlcore-${{ github.ref_name }} + # Where the PR will be made to. + BASE_REPO: flathub/dev.goats.xivlauncher + BASE_BRANCH: master steps: - name: Checkout uses: actions/checkout@v3 @@ -32,6 +38,19 @@ jobs: with: dotnet-version: 6.0.x # Set this to be the same as the projects required dotnet version. + - name: Setup Python3 + uses: actions/setup-python@v4 + with: + python-version: 3.x + + - name: Setup Flatpak + run: | + sudo apt update -y + sudo apt install flatpak -y + flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo + flatpak install --user org.freedesktop.Sdk.Extension.dotnet6/x86_64/22.08 -y # Update this when needed. + flatpak install --user org.freedesktop.Sdk/x86_64/22.08 -y # As well as this, if dependency generation is failing. + - name: Dotnet Restore working-directory: ./src/XIVLauncher.Core/ run: dotnet restore @@ -48,19 +67,6 @@ jobs: working-directory: ./src/XIVLauncher.Core/ run: dotnet build --configuration Release -p:DefineConstants=WINE_XIV_FEDORA_LINUX --no-restore -o ./dist/XIVLauncher.Core-fedora - - name: Setup Python3 - uses: actions/setup-python@v4 - with: - python-version: 3.x - - - name: Setup Flatpak - run: | - sudo apt update -y - sudo apt install flatpak -y - flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo - flatpak install --user org.freedesktop.Sdk.Extension.dotnet6/x86_64/22.08 -y # Update this when needed. - flatpak install --user org.freedesktop.Sdk/x86_64/22.08 -y # As well as this, if dependency generation is failing. - - name: Generate nuget-dependencies.json working-directory: ./src/XIVLauncher.Core/ run: | @@ -76,39 +82,57 @@ jobs: - name: Make PR to Flatpak repository run: | - echo ${{ secrets.PUSH_TOKEN }}| gh auth login --with-token + # Authenticate with GitHub CLI. + echo ${{ secrets.PUSH_TOKEN }} | gh auth login --with-token - git clone https://${{ secrets.PUSH_TOKEN }}@github.com/flathub/dev.goats.xivlauncher /tmp/xlcore-flatpak - mv ./src/XIVLauncher.Core/nuget-dependencies.json /tmp/xlcore-flatpak/ - mv ./.github/scripts/update_flatpak_manifest.py /tmp/xlcore-flatpak/ - cd /tmp/xlcore-flatpak + # Clone the repository we want to make the PR to. + gh repo fork ${{ env.BASE_REPO }} --clone=true --remote=true /tmp/xlcore-flatpak + + # Create a new branch for the PR. + git -C /tmp/xlcore-flatpak checkout -b ${{ env.HEAD_BRANCH }} + # Copy the files we need to the forked repository. + cp ./src/XIVLauncher.Core/nuget-dependencies.json /tmp/xlcore-flatpak/ + cp ./.github/scripts/update_flatpak_manifest.py /tmp/xlcore-flatpak/ + + # Update the manifest. + cd /tmp/xlcore-flatpak python3 -m pip install pyyaml - python3 update_flatpak_manifest.py dev.goats.xivlauncher.yml dev.goats.xivlauncher.appdata.xml $(echo ${{ github.ref_name }} | sed -e "s/^v//g") ${{ github.sha }} + python3 update_flatpak_manifest.py dev.goats.xivlauncher.yml dev.goats.xivlauncher.appdata.xml ${{ github.ref_name }} ${{ github.sha }} rm update_flatpak_manifest.py - git checkout -b xlcore-${{ github.ref_name }} + # Commit the changes. git add . - git commit -m "Update XIVLauncher.Core to ${{ github.ref_name }}" - git push --set-upstream origin xlcore-${{ github.ref_name }} + git commit -m "Update to ${{ github.ref_name }}" + + # Get the remote url and splice the token into it. + REMOTE_URL=$(git remote get-url origin) + REMOTE_URL=${REMOTE_URL/https:\/\//https:\/\/${{ secrets.PUSH_TOKEN }}@} + git remote set-url origin $REMOTE_URL + + # Push the changes to the fork. + git remote -v + git push --set-upstream origin ${{ env.HEAD_BRANCH }} - gh pr create -t "Update XIVLauncher.Core to ${{ github.ref_name }}" -b "This is an automated pull request" -B master + # Make a PR from the fork to the upstream repository. + gh pr create --repo ${{ env.BASE_REPO }} --title "Update to ${{ github.ref_name }}" --body "This PR was automatically generated by GitHub Actions." - - name: Zip Release + - name: Compress release files run: | sudo apt install zip -y mkdir -p ./dist - zip -r ./dist/XIVLauncher.Core.zip ./src/XIVLauncher.Core/dist/XIVLauncher.Core/ - zip -r ./dist/XIVLauncher.Core-arch.zip ./src/XIVLauncher.Core/dist/XIVLauncher.Core-arch/ - zip -r ./dist/XIVLauncher.Core-fedora.zip ./src/XIVLauncher.Core/dist/XIVLauncher.Core-fedora/ + # remove leading directories + tar -czf ./dist/XIVLauncher.Core.tar.gz -C ./src/XIVLauncher.Core/dist/XIVLauncher.Core . + tar -czf ./dist/XIVLauncher.Core-arch.tar.gz -C ./src/XIVLauncher.Core/dist/XIVLauncher.Core-arch . + tar -czf ./dist/XIVLauncher.Core-fedora.tar.gz -C ./src/XIVLauncher.Core/dist/XIVLauncher.Core-fedora . - name: Release on GitHub uses: softprops/action-gh-release@v1 with: generate_release_notes: true - #body_path: .github/release_notices.md # If you want to add notes to the top of all releases, uncomment this - append_body: true # and this to make sure they are appended, not replacing the original. + # body_path: .github/release_notices.md + # append_body: true # and this to make sure they are appended, not replacing the original. files: | - ./dist/XIVLauncher.Core.zip - ./dist/XIVLauncher.Core-arch.zip - ./dist/XIVLauncher.Core-fedora.zip + ./dist/XIVLauncher.Core.tar.gz + ./dist/XIVLauncher.Core-arch.tar.gz + ./dist/XIVLauncher.Core-fedora.tar.gz