diff --git a/RELEASE.md b/RELEASE.md index 16d43201..98baff6a 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -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: diff --git a/flatpak/generate-golang-dependencies.py b/flatpak/generate-golang-dependencies.py new file mode 100755 index 00000000..4477c2fc --- /dev/null +++ b/flatpak/generate-golang-dependencies.py @@ -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.") + diff --git a/flatpak/meek-client/go.mod.yml b/flatpak/meek-client/go.mod.yml index d522bd34..4abcdd2d 100644 --- a/flatpak/meek-client/go.mod.yml +++ b/flatpak/meek-client/go.mod.yml @@ -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 diff --git a/flatpak/obfs4proxy/go.mod.yml b/flatpak/obfs4proxy/go.mod.yml index bc93f738..097e9f23 100644 --- a/flatpak/obfs4proxy/go.mod.yml +++ b/flatpak/obfs4proxy/go.mod.yml @@ -1,4 +1,3 @@ -# Workaround for Go modules generated by github.com/dennwc/flatpak-go-mod - dest: vendor path: obfs4proxy/modules.txt type: file diff --git a/flatpak/snowflake/go.mod.yml b/flatpak/snowflake/go.mod.yml index 7d465886..e77dec25 100644 --- a/flatpak/snowflake/go.mod.yml +++ b/flatpak/snowflake/go.mod.yml @@ -1,4 +1,3 @@ -# Workaround for Go modules generated by github.com/dennwc/flatpak-go-mod - dest: vendor path: snowflake/modules.txt type: file