Skip to content

Commit

Permalink
Build the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Aug 11, 2023
1 parent 4f43833 commit e728521
Show file tree
Hide file tree
Showing 42 changed files with 90 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Ballerina Microsoft Excel Connector
===================

[![Build Status](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/workflows/CI/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/ballerina-platform/module-ballerinax-microsoft.excel/branch/master/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/module-ballerinax-microsoft.excel)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerinax-microsoft.excel.svg)](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/commits/master)
[![GraalVM Check](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/actions/workflows/build-with-bal-test-native.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/actions/workflows/build-with-bal-test-native.yml)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
Expand All @@ -26,11 +27,11 @@ Execute the commands below to build from the source after installing Ballerina.

1. To build the package:
```
bal pack ./excel
bal build ./ballerina
```
2. To run tests after build:
```
bal test ./excel
bal test ./ballerina
```
## Contributing to Ballerina
As an open source project, Ballerina welcomes contributions from the community.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion excel/Module.md → ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ Following is an example on how to add a worksheet using the connector.

2. Use `bal run` command to compile and run the Ballerina program.

**[You can find a list of samples here](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/tree/master/samples)**
**[You can find a list of samples here](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel/tree/master/examples)**
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Examples

This directory contains a collection of sample code examples written in Ballerina. These examples demonstrate various
use cases of the module. You can follow the instructions below to build and run these examples.

## Running an Example

Execute the following commands to build an example from the source.

* To build an example

`bal build <example-name>`


* To run an example

`bal run <example-name>`

## Building the Examples with the Local Module

**Warning**: Because of the absence of support for reading local repositories for single Ballerina files, the bala of
the module is manually written to the central repository as a workaround. Consequently, the bash script may modify your
local Ballerina repositories.

Execute the following commands to build all the examples against the changes you have made to the module locally.

* To build all the examples

`./build.sh build`


* To run all the examples

`./build.sh run`
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions examples/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

BAL_EXAMPLES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BAL_CENTRAL_DIR="$HOME/.ballerina/repositories/central.ballerina.io/"
BAL_HOME_DIR="$BAL_EXAMPLES_DIR/../ballerina"

set -e

case "$1" in
build)
BAL_CMD="build"
;;
run)
BAL_CMD="run"
;;
*)
echo "Invalid command provided: '$1'. Please provide 'build' or 'test' as the command."
exit 1
;;
esac

# Read Ballerina package name
BAL_PACKAGE_NAME=$(awk -F'"' '/^name/ {print $2}' "$BAL_HOME_DIR/Ballerina.toml")

# Push the package to the local repository
cd "$BAL_HOME_DIR" &&
bal pack &&
bal push --repository=local

# Remove the cache directories in the repositories
cacheDirs=($(ls -d "$BAL_CENTRAL_DIR"/cache-* 2>/dev/null))
for dir in "${cacheDirs[@]}"; do
[ -d "$dir" ] && rm -r "$dir"
done
echo "Successfully cleaned the cache directories"

# Update the central repository
BAL_DESTINATION_DIR="$HOME/.ballerina/repositories/central.ballerina.io/bala/ballerinax/$BAL_PACKAGE_NAME"
BAL_SOURCE_DIR="$HOME/.ballerina/repositories/local/bala/ballerinax/$BAL_PACKAGE_NAME"
[ -d "$BAL_DESTINATION_DIR" ] && rm -r "$BAL_DESTINATION_DIR"
[ -d "$BAL_SOURCE_DIR" ] && cp -r "$BAL_SOURCE_DIR" "$BAL_DESTINATION_DIR"
echo "Successfully updated the local central repositories"

# Loop through examples in the examples directory
find "$BAL_EXAMPLES_DIR" -type f -name "*.bal" | while read -r BAL_EXAMPLE_FILE; do
bal "$BAL_CMD" --offline "$BAL_EXAMPLE_FILE"
done
File renamed without changes.
4 changes: 2 additions & 2 deletions samples/create_column.bal → examples/create_column.bal
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ excel:Client excelClient = check new (configuration);
public function main() {
json[][] values = [["a3"], ["c3"], ["aa"]];
int columnIndex = 1;
excel:Column|error response = excelClient->createColumn(workbookIdOrPath, "sheetName", "tableName", values,

excel:Column|error response = excelClient->createColumn(workbookIdOrPath, "sheetName", "tableName", values,
columnIndex);
if (response is excel:Column) {
log:printInfo(response.toString());
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion samples/update_chart.bal → examples/update_chart.bal
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function main() {
left: 99
};

excel:Worksheet|error response = excelClient->updateChart(workbookIdOrPath, "worksheetName", "chartName",
excel:Worksheet|error response = excelClient->updateChart(workbookIdOrPath, "worksheetName", "chartName",
updateChart);
if (response is excel:Worksheet) {
log:printInfo(response.toString());
Expand Down
2 changes: 1 addition & 1 deletion samples/update_column.bal → examples/update_column.bal
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ excel:ConnectionConfig configuration = {
excel:Client excelClient = check new (configuration);

public function main() {
excel:Column|error response = excelClient->updateColumn(workbookIdOrPath, "sheetName", "tableName", 1,
excel:Column|error response = excelClient->updateColumn(workbookIdOrPath, "sheetName", "tableName", 1,
name = "columnName");
if (response is excel:Column) {
log:printInfo(response.toString());
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e728521

Please sign in to comment.