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

ci: add ci workflow #3

Merged
merged 2 commits into from
Jul 17, 2024
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
96 changes: 96 additions & 0 deletions .github/workflows/release_wasm_fdw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Release


on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+' # Push events to matching wasm fdw tag, i.e. v1.0.2

permissions:
contents: write

jobs:
release:
name: Create Wasm FDW Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Rust
run: |
# install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain stable && \
rustup --version && \
rustc --version && \
cargo --version

# add wasm32-unknown-unknown target
rustup target add wasm32-unknown-unknown

# install Wasm component
cargo install cargo-component --locked

- name: Build Wasm FDW
run: |
cargo component build --release --target wasm32-unknown-unknown

- name: Calculate Wasm file checksum
uses: jmgilman/actions-generate-checksum@v1
with:
method: sha256
output: checksum.txt
patterns: |
./target/wasm32-unknown-unknown/release/*.wasm

- name: Get project metadata JSON
id: metadata
run: |
METADATA_JSON=`cargo metadata --format-version 1 --no-deps --offline`
echo "METADATA_JSON=$METADATA_JSON" >> "$GITHUB_OUTPUT"

- name: Extract package info
id: extract
env:
TAG: ${{ github.ref_name }}
run: |
PACKAGE="${{ fromJson(steps.metadata.outputs.METADATA_JSON).packages[0].metadata.component.package }}"
VERSION=`echo "${TAG}" | sed -E 's/v(.*)/\1/'`
CHECKSUM=`head -1 checksum.txt | sed -E 's/^(.*) .*/\1/'`
echo "PACKAGE=$PACKAGE" >> "$GITHUB_OUTPUT"
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "CHECKSUM=$CHECKSUM" >> "$GITHUB_OUTPUT"

- name: Create README.txt
env:
PACKAGE: ${{ steps.extract.outputs.PACKAGE }}
VERSION: ${{ steps.extract.outputs.VERSION }}
CHECKSUM: ${{ steps.extract.outputs.CHECKSUM }}
run: |
cat > README.txt <<EOF
To use this Wasm foreign data wrapper on Supabase, create a foreign server like below,

create server example_server
foreign data wrapper wasm_wrapper
options (
fdw_package_url 'https://github.com/supabase-community/wasm-fdw-example/releases/download/v${VERSION}/wasm_fdw_example.wasm',
fdw_package_name '${PACKAGE}',
fdw_package_version '${VERSION}',
fdw_package_checksum '${CHECKSUM}',
api_url 'https://api.github.com'
);

For more detials, please visit https://github.com/supabase-community/wasm-fdw-example.
EOF

- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
make_latest: true
files: |
README.txt
checksum.txt
./target/wasm32-unknown-unknown/release/*.wasm

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ target/
*.a
*.swp
*.log
site/
.bash_history
.config/
cmake*/
.direnv
src/bindings.rs
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ This example reads the [realtime GitHub events](https://api.github.com/events) i

```bash
├── src
│   ├── bindings.rs # Wasm package bindings file which is generated by the Component Model, we don't need to change it.
│   └── lib.rs # The package source code. We will implement the FDW logic, in this file.
├── supabase-wrappers-wit # The Wasm Interface Type provided by Supabase. See below for a detailed description.
│   ├── http.wit
Expand Down Expand Up @@ -95,7 +94,7 @@ This will build the Wasm file in `target/wasm32-unknown-unknown/release/wasm_fdw

## Use with Supabase

You can use your Wasm FDW on the Supabase platform as long as the Wrappers extension version is `>=0.4.2`.
You can use your Wasm FDW on the Supabase platform as long as the Wrappers extension version is `>=0.4.1`.

### Checking Wrappers version

Expand All @@ -119,16 +118,18 @@ create foreign data wrapper wasm_wrapper
validator wasm_fdw_validator;
```

Create foreign server and foreign table:
Create foreign server and foreign table like below,

```sql
create server example_server
foreign data wrapper wasm_wrapper
options (
-- change the url to your Wasm package url
fdw_package_url 'https://github.com/supabase/wasm-fdw-example/releases/download/wasm_fdw_example_v0.1.0/wasm_fdw_example.wasm',
-- change below fdw_pacakge_* options accordingly
-- check available releases at https://github.com/supabase-community/wasm-fdw-example/releases
fdw_package_url 'https://github.com/supabase-community/wasm-fdw-example/releases/download/v0.1.0/wasm_fdw_example.wasm',
fdw_package_name 'my-company:example-fdw',
fdw_package_version '0.1.0',
fdw_package_checksum '7d0b902440ac2ef1af85d09807145247f14d1d8fd4d700227e5a4d84c8145409',
api_url 'https://api.github.com'
);

Expand Down Expand Up @@ -206,6 +207,11 @@ lto = true
cargo component build --release --target wasm32-unknown-unknown
```

### Automation

If you host source code on GitHub, the building and release process can be automated, take a look at the `.github/workflow/release_wasm_fdw.yml` file to see an example of CI workflow.


## Other examples

Some other Wasm foreign data wrapper projects developed by Supabase team:
Expand Down
Loading