Make a script that generates the golang dependencies and adjusts the yaml as required

This commit is contained in:
Miguel Jacq 2025-02-08 17:54:51 +11:00
parent bab72f53c1
commit a9dba8d0a0
No known key found for this signature in database
GPG Key ID: 59B3F0C24135C6A9
5 changed files with 73 additions and 29 deletions

View File

@ -94,34 +94,10 @@ With every commit to the `main` branch, Snapcraft's CI should trigger builds. Ma
In `flatpak/org.onionshare.OnionShare.yaml`:
- [ ] Update `tor` and `libevent`
- [ ] Update `obfs4proxy`, `meek-client`, and `snowflake-client` dependencies. To do this, clone the latest tagged release of the following repositories, into a temp directory:
```
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/meek.git
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
https://gitlab.com/yawning/obfs4.git
```
Enter into each directory (having checked out the correct tag) and run:
- [ ] Update `obfs4proxy`, `meek-client`, and `snowflake-client` dependencies. To do this, edit the script `flatpak/generate-golang-dependencies.py` and make sure that the repository URLs and tags are the latest versions. Then run this command from the root of the onionshare repository folder:
```sh
go run github.com/dennwc/flatpak-go-mod@latest .
```
This will generate several files:
```
go.mod.yml
modules.txt
```
Move the `go.mod.yml` into the respective `flatpak/snowflake`, `flatpak/obfs4proxy` and `flatpak/meek-client` folders.
Then edit the go.mod.yml in each one and edit the 'path' attribute of the first entry that it has the subfolder set (below example is just the `obfs4proxy/go.mod.yml`, but you should do the same for the other two):
```
- dest: vendor
path: obfs4proxy/modules.txt
type: file
./flatpak/generate-golang-dependencies.py
```
- [ ] Update the Python dependencies. This is super hacky. You need to use both the poetry and pip parts of [this tool](https://github.com/flatpak/flatpak-builder-tools), but the version from [this PR](https://github.com/flatpak/flatpak-builder-tools/pull/353):
@ -138,6 +114,7 @@ In `flatpak/org.onionshare.OnionShare.yaml`:
../flatpak-json2yaml.py ./python3-modules.json
mv python3-modules.yml onionshare-desktop.yaml
```
Now, move `onionshare-desktop.yaml` and `onionshare-cli.yaml` into the `flatpak/` folder.
- [ ] Build and test the Flatpak package to ensure it works:

View File

@ -0,0 +1,70 @@
#!/usr/bin/env python3
import os
import subprocess
import yaml
import shutil
import tempfile
# Define the repositories, tags, and subfolders
repos = [
{"url": "https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/meek.git", "tag": "v0.38.0", "subfolder": "meek-client"},
{"url": "https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git", "tag": "v2.10.0", "subfolder": "snowflake"},
{"url": "https://gitlab.com/yawning/obfs4.git", "tag": "obfs4proxy-0.0.14", "subfolder": "obfs4proxy"},
]
# Folder to store flatpak files
flatpak_folder = os.path.join(os.getcwd(), 'flatpak')
# Create the flatpak folder and subfolders
if not os.path.exists(flatpak_folder):
raise RuntimeError("You do not appear to be in the onionshare repository. Please cd into it first")
# Function to run a shell command and get the output
def run_command(command, path):
result = subprocess.run(command, shell=True, check=True, text=True, capture_output=True, cwd=path)
return result.stdout
# Process each repository
for repo in repos:
repo_url = repo["url"]
tag = repo["tag"]
subfolder = repo["subfolder"]
# Clone the repository
repo_name = repo_url.split('/')[-1].replace('.git', '')
with tempfile.TemporaryDirectory() as td:
print(f"Cloning {repo_url} to {td}/{subfolder}")
run_command(f"git clone {repo_url} {subfolder}", td)
# Checkout the specific tag
print(f"Checking out {tag}")
run_command(f"git checkout {tag}", f"{td}/{subfolder}")
# Run the go command
print(f"Running the dennwc/flatpak-go-mod to generate sources")
run_command("go run github.com/dennwc/flatpak-go-mod@latest .", f"{td}/{subfolder}")
# Copy go.mod.yml and modules.txt to the appropriate subfolder
os.makedirs(os.path.join(flatpak_folder, subfolder), exist_ok=True)
print(f"Copying go.mod.yml and modules.txt to {flatpak_folder}/{subfolder}")
shutil.copy(f"{td}/{subfolder}/go.mod.yml", os.path.join(flatpak_folder, subfolder, "go.mod.yml"))
shutil.copy(f"{td}/{subfolder}/modules.txt", os.path.join(flatpak_folder, subfolder, "modules.txt"))
# Edit the go.mod.yml to change the path to include the subfolder
go_mod_path = os.path.join(flatpak_folder, subfolder, "go.mod.yml")
with open(go_mod_path, 'r') as f:
go_mod_data = yaml.safe_load(f)
# Traverse the YAML data to find the path: modules.txt and update it
for item in go_mod_data:
if isinstance(item, dict) and item.get('path') == 'modules.txt':
print(f"Renaming the reference to modules.txt in {flatpak_folder}/{subfolder}/go.mod.yml to include the subfolder path {subfolder}")
item['path'] = f'{subfolder}/modules.txt'
# Save the edited go.mod.yml
with open(go_mod_path, 'w') as f:
yaml.safe_dump(go_mod_data, f)
print("Process completed.")

View File

@ -1,4 +1,3 @@
# Workaround for Go modules generated by github.com/dennwc/flatpak-go-mod
- dest: vendor
path: meek-client/modules.txt
type: file

View File

@ -1,4 +1,3 @@
# Workaround for Go modules generated by github.com/dennwc/flatpak-go-mod
- dest: vendor
path: obfs4proxy/modules.txt
type: file

View File

@ -1,4 +1,3 @@
# Workaround for Go modules generated by github.com/dennwc/flatpak-go-mod
- dest: vendor
path: snowflake/modules.txt
type: file