Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add appstream support to flathub update script + Add artifacts to releases #27

Merged
merged 6 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions .github/scripts/update_flatpak_manifest.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
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]} <config file> <new tag number> <new commit hash>')
print("Ran with args: " + str(sys.argv))
if len(sys.argv) != 5:
print(f'Usage: python3 {sys.argv[0]} <manifest file> <appstream file> <new tag> <new commit>')
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")}')
38 changes: 8 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,41 +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: |
rm -rf bin
dotnet build --configuration Release --no-restore

- name: Upload Artifact (Default)
uses: actions/upload-artifact@v3
with:
name: XIVLauncher.Core-default
path: ./src/XIVLauncher.Core/bin/
run: dotnet build --configuration Release --no-restore -o ./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/
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: |
rm -rf bin
dotnet build --configuration Release -p:DefineConstants=WINE_XIV_FEDORA_LINUX --no-restore
run: dotnet build --configuration Release -p:DefineConstants=WINE_XIV_FEDORA_LINUX --no-restore -o ./dist/XIVLauncher.Core-fedora

- name: Upload Artifacts (Fedora)
uses: actions/upload-artifact@v3
with:
name: XIVLauncher.Core-fedora
path: ./src/XIVLauncher.Core/bin/
- name: Dotnet Test
run: dotnet test --no-build --verbosity normal
97 changes: 73 additions & 24 deletions .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
name: "PR XLCore to Flatpak"
name: "Release XLCore"

on:
push:
tags:
- "v*"
- "*.*.*"

permissions:
contents: write

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
Expand All @@ -27,15 +36,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

- name: Dotnet Restore
working-directory: ./src/XIVLauncher.Core/
run: dotnet restore

- name: Dotnet Build
working-directory: ./src/XIVLauncher.Core/
run: dotnet build --configuration Release --no-restore
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
Expand All @@ -47,8 +48,24 @@ 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: 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: Generate nuget-dependencies.json
working-directory: ./src/XIVLauncher.Core/
Expand All @@ -65,25 +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 $(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 }}

# 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: Compress release files
run: |
sudo apt install zip -y
mkdir -p ./dist
# 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 .

gh pr create -t "Update XIVLauncher.Core to ${{ github.ref_name }}" -b "This is an automated pull request" -B master

- name: Release on GitHub
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
# 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.tar.gz
./dist/XIVLauncher.Core-arch.tar.gz
./dist/XIVLauncher.Core-fedora.tar.gz