diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8eab089 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,131 @@ +name: Release to PlatformIO Registry + +on: + release: + types: [published] + workflow_dispatch: + inputs: + dry_run: + description: 'Dry run (pack only, do not publish)' + required: false + type: boolean + default: true + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout tag + uses: actions/checkout@v4 + with: + ref: ${{ github.event.release.tag_name || github.ref }} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install platformio + + - name: Verify versions + run: | + # Extract version from library.json + LIBRARY_JSON_VERSION=$(python -c "import json; print(json.load(open('library.json'))['version'])") + + # Extract version from library.properties + LIBRARY_PROPERTIES_VERSION=$(grep '^version=' library.properties | cut -d'=' -f2) + + echo "library.json version: $LIBRARY_JSON_VERSION" + echo "library.properties version: $LIBRARY_PROPERTIES_VERSION" + + # Check library.json and library.properties match + if [ "$LIBRARY_JSON_VERSION" != "$LIBRARY_PROPERTIES_VERSION" ]; then + echo "❌ ERROR: Version mismatch between library.json and library.properties!" + echo "library.json: $LIBRARY_JSON_VERSION" + echo "library.properties: $LIBRARY_PROPERTIES_VERSION" + exit 1 + fi + + echo "✅ library.json and library.properties versions match: $LIBRARY_JSON_VERSION" + + # For release events or tags, verify tag matches library version + if [ "${{ github.event_name }}" == "release" ] || [ "${{ github.ref_type }}" == "tag" ]; then + if [ "${{ github.event_name }}" == "release" ]; then + TAG_NAME="${{ github.event.release.tag_name }}" + else + TAG_NAME="${{ github.ref_name }}" + fi + + # Strip leading 'v' from tag + TAG_VERSION="${TAG_NAME#v}" + + echo "Tag version: $TAG_VERSION (from tag: $TAG_NAME)" + + if [ "$LIBRARY_JSON_VERSION" != "$TAG_VERSION" ]; then + echo "❌ ERROR: Tag version mismatch!" + echo "Tag version '$TAG_VERSION' does not match library version '$LIBRARY_JSON_VERSION'" + echo "Please ensure the tag matches the version in library.json (e.g., tag v1.45 for version 1.45)" + exit 1 + fi + + echo "✅ Tag version verified: $TAG_VERSION" + else + echo "ℹ️ Running on non-tag ref '${{ github.ref_name }}', skipping tag version check" + fi + + - name: Run offline tests compile + run: | + cd tests + pio test --environment esp32dev --without-uploading --without-testing + + - name: Run native HTTP parser tests + run: | + cd tests/test_http_parser + pio test -e native + + - name: Pack library + id: pack + run: | + # Pack to /tmp to avoid including the tarball in the working directory + pio pkg pack --output /tmp/Web3E-package.tar.gz + echo "package_path=/tmp/Web3E-package.tar.gz" >> $GITHUB_OUTPUT + + # Show package contents + echo "📦 Package contents:" + tar -tzf /tmp/Web3E-package.tar.gz | head -50 + + # Count total files + FILE_COUNT=$(tar -tzf /tmp/Web3E-package.tar.gz | wc -l) + echo "Total files in package: $FILE_COUNT" + + - name: Publish to PlatformIO Registry + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.dry_run == false) + env: + PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }} + run: | + echo "Publishing Web3E to PlatformIO Registry..." + pio pkg publish ${{ steps.pack.outputs.package_path }} --type library --owner alphawallet --no-interactive + + - name: Upload package artifact (dry run) + if: github.event_name == 'workflow_dispatch' && inputs.dry_run == true + uses: actions/upload-artifact@v4 + with: + name: web3e-package + path: ${{ steps.pack.outputs.package_path }} + retention-days: 30 + + - name: Attach package to GitHub Release + if: github.event_name == 'release' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${{ github.event.release.tag_name }} \ + ${{ steps.pack.outputs.package_path }} \ + --clobber diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..d2ecd55 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,81 @@ +# Releasing Web3E + +This document describes the process for releasing a new version of Web3E to the PlatformIO Registry. + +## Release Process + +1. **Update Version** + - Increment the `version` field in `library.json` (e.g., from `1.45` to `1.46`) + - Increment the `version` field in `library.properties` to match + - Commit the version bump to a PR and get it reviewed + +2. **Merge to Master** + - Merge the PR with the version bump into `master` + - Ensure all CI checks pass + +3. **Create GitHub Release** + - Go to [GitHub Releases](https://github.com/AlphaWallet/Web3E/releases) + - Click "Draft a new release" + - Create a new tag matching the version with a `v` prefix (e.g., `v1.46` for version `1.46`) + - Set the target to `master` + - Write release notes describing the changes + - Click "Publish release" + +4. **Automated Publishing** + - The `release.yml` GitHub Actions workflow will automatically: + - Verify the tag matches the `library.json` version + - Run offline tests to ensure the library compiles + - Run native tests (HTTP parser) + - Pack the library (excluding tests, tools, and dev files) + - Publish to the [PlatformIO Registry](https://registry.platformio.org/libraries/alphawallet/Web3E) + - Attach the packed library tarball to the GitHub Release + +5. **Verify Release** + - Check the [Actions tab](https://github.com/AlphaWallet/Web3E/actions) to ensure the workflow completed successfully + - Verify the new version appears on the [PlatformIO Registry](https://registry.platformio.org/libraries/alphawallet/Web3E) + - Check that the tarball was attached to the GitHub Release + +## Testing the Release Workflow + +You can test the release workflow without publishing by using the manual workflow dispatch: + +1. Go to [Actions → Release to PlatformIO Registry](https://github.com/AlphaWallet/Web3E/actions/workflows/release.yml) +2. Click "Run workflow" +3. Keep "Dry run" checked (default: true) +4. Select a branch/tag +5. Click "Run workflow" + +In dry run mode, the workflow will: +- Verify the version +- Run all tests +- Pack the library +- Upload the tarball as a workflow artifact (instead of publishing) + +## Version Mismatch + +If the tag version doesn't match the `library.json` version, the workflow will fail with a clear error message. For example: + +- ✅ Tag `v1.45` with `library.json` version `1.45` → Success +- ❌ Tag `v1.46` with `library.json` version `1.45` → Fail + +Always ensure the version in `library.json` is bumped and merged to master before creating the release. + +## What Gets Published + +The library package includes: +- `src/` - Source code +- `examples/` - Example projects +- `library.json` - Library metadata +- `library.properties` - Arduino library metadata + +The following are excluded from the package (see `library.json` → `export.exclude`): +- `tests/` - Test suite +- `test-consumer/` - Test consumer project +- `tools/` - Development tools +- `.github/` - GitHub workflows +- `docs/` - Documentation +- Build artifacts and caches + +## Requirements + +The workflow requires the `PLATFORMIO_AUTH_TOKEN` secret to be set in the repository. This should be configured by the repository administrator. diff --git a/library.json b/library.json index d48f7ee..e0470ff 100644 --- a/library.json +++ b/library.json @@ -32,5 +32,20 @@ ], "name": "Web3E", "version": "1.45", - "homepage": "https://www.smarttokenlabs.com/" + "homepage": "https://www.smarttokenlabs.com/", + "export": { + "exclude": [ + "tests", + "test-consumer", + "tools", + ".github", + ".git", + ".gitignore", + ".vscode", + "docs", + "*.log", + ".pio", + ".platformio" + ] + } } \ No newline at end of file