Skip to content
Closed
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
125 changes: 125 additions & 0 deletions .github/workflows/deploy_and_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Deploy to IPFS and create release
run-name: Deploy to IPFS and create release

on:
pull_request:
branches:
- dev
push:
branches:
- dev

jobs:
deploy-and-release:
runs-on: ubuntu-20.04
permissions:
contents: write
packages: write
id-token: write
pull-requests: write
container:
image: ghcr.io/cirruslabs/flutter:3.29.0
options: --privileged
steps:
# https://github.com/marketplace/actions/checkout
- uses: actions/checkout@main

- name: Setup version for branch WORKING
if: github.event_name == 'pull_request'
run: |
RELEASE_VER="0.0.1"
echo "RELEASE_VER=$RELEASE_VER" >> $GITHUB_ENV

- name: Setup version for branch DEV
if: github.event_name == 'push'
run: |
chmod -R 777 scripts
RELEASE_VER="$(./scripts/version.sh)"
echo "RELEASE_VER=$RELEASE_VER" >> $GITHUB_ENV

# TODO: Replace hardcoded values with secrets for production:
# TORII_LOG_ACCESS_TOKEN="${{ secrets.TORII_LOG_ACCESS_TOKEN }}"
# TORII_LOG_URL="${{ secrets.TORII_LOG_URL }}"
- name: Create .env file
run: |
cat <<EOF > .env
TORII_LOG_ACCESS_TOKEN="lafijsiadnm/a@@#lsa\$fd8f"
TORII_LOG_URL="http://157.180.16.117:8890/"
KIRA_ETH_ENABLED=false
IS_TEST_ENVIRONMENT=false
EOF

- name: Build web version
run: |
flutter build web --web-renderer canvaskit --dart-define-from-file=.env
sed -i 's/base href="\/"/base href=\".\/\"/' ./build/web/index.html
cd ./build/web
zip -r ../../html-web-app.zip ./*
cd ../..

- name: Pin/Upload files to IPFS
run: |
IPFS_HASH=""
IPFS_UPLOAD_NAME=torii-www-$RELEASE_VER

bash-utils timerStart "pin-timeout"

while [ -z "$IPFS_HASH" ] || [ $(bash-utils timerSpan "pin-timeout") -gt 120 ]; do
bash-utils echoInfo "INFO: Attempting files pin to IPFS..."
[ -e ./ipfs-pin.log ] && rm ./ipfs-pin.log
touch ./ipfs-pin.log
ipfs-api delete $IPFS_UPLOAD_NAME --key=${{secrets.PINATA_API_JWT}} --verbose=true || echo "WARNING: Failed to delete file with name '$IPFS_UPLOAD_NAME' request failed or it might not exist"
ipfs-api pin ./build/web $IPFS_UPLOAD_NAME --key=${{secrets.PINATA_API_JWT}} --verbose=true | tee -a ./ipfs-pin.log || echo "ERROR: Failed to pin web app"
IPFS_HASH=$(cat ./ipfs-pin.log | tail -n 1 | bash-utils jsonParse ".hash" || echo "")
sleep 10
done

echo "IPFS_HASH=$IPFS_HASH" >> $GITHUB_ENV

echo "Private Gateway: https://ipfs.kira.network/ipfs/$IPFS_HASH"
echo "Public Gateway: https://ipfs.io/ipfs/$IPFS_HASH"
echo "Released version: $RELEASE_VER"
echo "Released Date Time: $(date --rfc-2822)"

- name: Create RELEASE.md
if: github.event_name == 'push'
run: |
touch README.md
echo "Private Gateway: https://ipfs.kira.network/ipfs/$IPFS_HASH" >> ./RELEASE.md
echo "Public Gateway: https://ipfs.io/ipfs/$IPFS_HASH" >> ./RELEASE.md
echo "\n\r\n\r\`\`\`" >> ./RELEASE.md
echo "Released Version: $RELEASE_VER" >> ./RELEASE.md
echo "Released Date Time: $(date --rfc-2822)" >> ./RELEASE.md
echo "html-web-app.zip: sha256:$(sha256sum ./html-web-app.zip | awk '{ print $1 }')" >> ./RELEASE.md
echo "\`\`\`" >> ./RELEASE.md

# Install the cosign tool
# ref.: https://github.com/sigstore/cosign-installer, v2.2.0
- name: Install Cosign
if: github.event_name == 'push'
uses: sigstore/cosign-installer@main
with:
cosign-release: 'v1.13.1'

- name: Signing release files
if: github.event_name == 'push'
env:
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
run: |
cosign version
cosign sign-blob --key=env://COSIGN_PRIVATE_KEY --output-signature=./html-web-app.zip.sig ./html-web-app.zip

# ref: https://github.com/softprops/action-gh-release, v0.1.14
- name: Publish release
if: github.event_name == 'push'
uses: softprops/action-gh-release@v1
with:
body_path: RELEASE.md
tag_name: ${{ env.RELEASE_VER }}
name: ${{ env.RELEASE_VER }}
draft: false
fail_on_unmatched_files: true
files: |
./html-web-app.zip
./html-web-app.zip.sig
66 changes: 66 additions & 0 deletions .github/workflows/version_and_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Version and tests check
run-name: Version and tests check

on:
pull_request:
branches:
- dev

jobs:
app-version-check:
runs-on: ubuntu-20.04
steps:
# https://github.com/marketplace/actions/checkout
- uses: actions/checkout@main
with:
ref: dev
- name: Extract version from branch DEV
run: |
chmod -R 777 scripts
DEV_BRANCH_VERSION="$(./scripts/version.sh)"
echo "DEV_BRANCH_VERSION=$DEV_BRANCH_VERSION" >> $GITHUB_ENV
echo "DEV_BRANCH_VERSION: $DEV_BRANCH_VERSION"
- uses: actions/checkout@main
- name: Extract version from branch WORKING
run: |
chmod -R 777 scripts
WORKING_BRANCH_VERSION="$(./scripts/version.sh)"
echo "WORKING_BRANCH_VERSION=$WORKING_BRANCH_VERSION" >> $GITHUB_ENV
echo "WORKING_BRANCH_VERSION: $WORKING_BRANCH_VERSION"
- name: Compare versions
run: |
echo "DEV_BRANCH_VERSION: $DEV_BRANCH_VERSION"
echo "WORKING_BRANCH_VERSION: $WORKING_BRANCH_VERSION"

RESULT="$(./scripts/compare_versions.py $DEV_BRANCH_VERSION $WORKING_BRANCH_VERSION)"

if [ $RESULT == "True" ]; then
exit 0
fi

echo "Working branch version isn't updated in file pubspec.yaml. Please update accordingly."
exit 1
run-unit-tests:
needs: app-version-check
runs-on: ubuntu-20.04
container:
image: ghcr.io/cirruslabs/flutter:3.29.0
steps:
# https://github.com/marketplace/actions/checkout
- uses: actions/checkout@main

# TODO: Replace hardcoded values with secrets for production:
# TORII_LOG_ACCESS_TOKEN="${{ secrets.TORII_LOG_ACCESS_TOKEN }}"
# TORII_LOG_URL="${{ secrets.TORII_LOG_URL }}"
- name: Create .env file
run: |
cat <<EOF > .env
TORII_LOG_ACCESS_TOKEN="lafijsiadnm/a@@#lsa\$fd8f"
TORII_LOG_URL="http://157.180.16.117:8890/"
KIRA_ETH_ENABLED=false
IS_TEST_ENVIRONMENT=true
EOF

- run: flutter pub get
- run: flutter analyze
- run: flutter test "test/unit" --platform chrome --null-assertions
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ locator.config.dart

# Test data
/assets/test

# Code review
CODE_REVIEW.md
131 changes: 131 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Contributing to Torii UI

## Development Workflow

### Branch Structure

- `dev` - Main development branch. All PRs should target this branch.

### Version Management

The app version is defined in `pubspec.yaml`:

```yaml
version: 1.0.0+1
```

**Important:** You must bump the version in `pubspec.yaml` for every PR to `dev`. The CI will reject PRs where the working branch version is not greater than the `dev` branch version.

### Scripts

Located in `/scripts`:

| Script | Purpose |
|--------|---------|
| `version.sh` | Extracts normalized version (X.Y.Z) from pubspec.yaml |
| `compare_versions.py` | Compares two versions, returns True if second > first |

### CI/CD Pipeline

#### On Pull Request to `dev`

1. **Version Check** (`version_and_tests.yaml`)
- Extracts version from `dev` branch
- Extracts version from your working branch
- Fails if working branch version ≤ dev branch version

2. **Unit Tests** (`version_and_tests.yaml`)
- Runs `flutter pub get`
- Runs `flutter analyze`
- Runs `flutter test "test/unit" --platform chrome`

3. **Build Preview** (`deploy_and_release.yaml`)
- Builds web app with canvaskit renderer
- Pins to IPFS with temporary version `0.0.1`
- No GitHub release created

#### On Push/Merge to `dev`

1. **Build** (`deploy_and_release.yaml`)
- Builds web app: `flutter build web --web-renderer canvaskit`
- Creates `html-web-app.zip`

2. **IPFS Deployment**
- Pins build to IPFS via Pinata
- Upload name: `torii-www-{version}`
- Available at:
- `https://ipfs.kira.network/ipfs/{hash}`
- `https://ipfs.io/ipfs/{hash}`

3. **GitHub Release**
- Creates release with tag matching version
- Signs `html-web-app.zip` with cosign
- Attaches:
- `html-web-app.zip`
- `html-web-app.zip.sig`

### Making a Contribution

1. Create a feature branch from `dev`:
```bash
git checkout dev
git pull origin dev
git checkout -b feature/my-feature
```

2. Make your changes

3. Bump version in `pubspec.yaml`:
```yaml
# Before
version: 1.0.0+1

# After (example)
version: 1.0.1+1
```

4. Run tests locally:
```bash
flutter pub get
flutter analyze
flutter test "test/unit" --platform chrome
```

5. Push and create PR targeting `dev`

6. Wait for CI checks to pass

7. Get review and merge

### Required Secrets (for maintainers)

The following GitHub secrets must be configured:

| Secret | Purpose |
|--------|---------|
| `PINATA_API_JWT` | Pinata API token for IPFS pinning |
| `COSIGN_PRIVATE_KEY` | Cosign private key for signing releases |
| `COSIGN_PASSWORD` | Password for cosign private key |

### Local Development

```bash
# Install dependencies
flutter pub get

# Generate code (routing, DI)
dart run build_runner build --delete-conflicting-outputs

# Generate translations
dart pub global run intl_utils:generate

# Run web version
flutter run -d chrome

# Build web version
flutter build web --web-renderer canvaskit
```

### Flutter Version

This project uses Flutter `3.29.0` (stable channel). Ensure you have a compatible version installed.
Loading
Loading