Sunday 24 April 2022

Deploy Flutter Web Application to GitHub Pages using GitHub Actions.

Here we are going to take advantage of GitHub pages and GitHub actions to deploy a web version of a flutter application for free. If you have not installed Flutter yet, follow the instructions in their web.

First of all we need to create a new flutter project:

flutter create flutter_to_ghpages_example

Onces the project is created:

cd flutter_to_ghpages_example/ flutter run -d chrome

With those commands we are going to run the example application on chrome (if you want to run it in a different browser you could execute: flutter devices to list all the available devices and choose one).

Now that we checked that everything works great on our computer is time for checking the source to git.

git init git add . git commit -m "Initial Commit" git branch -M main git remote add origin git@github.com:[UserName]/[RepositoryName].git git push -u origin main

Our initial code should be in our GitHub repository.

Before creating our workflow we need to create an empty branch named gh-pages:

git switch --orphan gh-pages git commit --allow-empty -m "Initial commit on orphan branch" git push origin gh-pages

With this branch pushed, and action will trigger to deploy our webpage:

But as we don't have any code, the web will have an error:

Lets deploy our initial web, for this we create a workflow that each time we push changes to main it will update one branch called gh-pages with the web build on it:

.github/workflows/CD-to-gh-pages.yml

name: CD to GitHub Pages on: push: branches: - main jobs: cd: runs-on: ubuntu-20.04 env: JAVA_VERSION: "11.0" FLUTTER_VERSION: "2.10.4" steps: - uses: actions/checkout@v2 - uses: actions/setup-java@v1 with: java-version: ${{env.JAVA_VERSION}} - uses: subosito/flutter-action@v2 with: flutter-version: ${{env.FLUTTER_VERSION}} - run: flutter pub get - run: flutter analyze - run: flutter test # Build the project on release web mode, also change the base-href to the repository name # because when you create a github page this is included on the url. - run: flutter build web --release --base-href="/${{ github.event.repository.name }}/" - run: | git config --global user.name '${{github.event.pusher.name}}' git config --global user.email '${{github.event.pusher.email}}' git add -f build/web git commit -m '[automated commit] releasing new web version.' git push origin `git subtree split --prefix build/web main`:gh-pages --force

This workflow will:

  1. Checkout the main branch.
  2. Install Java 11.0.
  3. Install Flutter 2.10.4
  4. Get the dependencies, analyze and test the code.
  5. Build the project on release web mode. It is important to change the base-href because the default value is / and on GitHub pages, the base URL is your repository name.
  6. Configure git with the credential of the person who made the push to main.
  7. Even though build folder is excluded on .gitignore we need to add build/web so we force it.
  8. A commit is created with the content on build/web.
  9. We are only interested on the content of build/web folder, so we create a subtree and push it to gh-pages branch.

After committing and pushing this changes to Github, a new Action run should be triggered:

When the execution of the workflow finishes, a new GitHub Pages deployment action will be running.

Now our code should be shown on the web:

Apparently everything is working properly, but lets demonstrate making a small change to the web. Lets change the title on lib/main.dart line 27:

Add the changes, commit and push to main.

All the code is available on this repository.

Sunday 26 October 2014

Kata 1 - FizzBuzz in Java ( step by step)


It has been a long time since the last time I wrote here. This time I'm going to write about a completely different thing.

One week ago I started reading about Katas and TDD. Since then I have been doing two Katas every day. With this I am improving my Java skills and learning how to use TDD.

TDD (Test-driven development) is a software development process  that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards.

KATA  is an exercise in programming which helps a programmer hone their skills through practice and repetition.

In this article I will do FizzBuzz Kata step by step. This is one of the easiest Katas.

FizzBuzz Kata has 4 easy rules :


  1. If the number is divisible by 3 should return "Fizz" .
  2. If the number is divisible by 5 should return "Buzz" .
  3. If the number is divisible by 15 should return "FizzBuzz" .
  4. If the number is not divisible by 3, 5 or 15 should return that number as String.

First of all you need an IDE with some unitary testing plugin. I am going to use eclipse with Junit because is the one that comes with it. You can do  Katas with the IDE you want, the unitary testing plugin you want and the programming language you prefer.

When you have your IDE ready, you have to create two classes, one FizzBuzzTest.java and FizzBuzz.java and put them in the same package.

Video step by step :



In the next video I will try to explain what I am doing, this is a first try.

For any question leave a comment.



Saturday 1 March 2014

Perfomance Dart Vs Dart2JS vs JavaScript Managing the DOM

After the result seen in the other post I decided to write this post about the performance of the browsers managing the DOM.

As in the other post, I have written a Dart code for inserting and removing an input from the DOM. I tried to do it as easy as I can. These are  the source codes :






The result are these :

NUMBERCREATEDELETETOTAL
Dartium DART
13,714,478,18
23,754,488,23
33,844,548,38
43,744,568,3
53,764,58,26
63,844,628,46
73,624,688,3
83,975,329,29
94,034,989,01
103,714,498,2
AVERAGE3,7974,6648,461
Chrome Dart2JS
10,244,354,59
20,253,824,07
30,243,633,87
40,233,563,79
50,243,693,93
60,244,334,57
70,254,044,29
80,243,623,86
90,243,84,04
100,243,733,97
AVERAGE0,2413,8574,098
Firefox Dart2JS
10,2621,7321,99
20,2221,4221,64
30,2320,9621,19
40,2322,9423,17
50,2321,4121,64
60,2320,6720,9
70,2320,8321,06
80,2320,6320,86
90,2320,9421,17
100,2320,7420,97
AVERAGE0,23221,22721,459
IE Dart2JS
10,9120,6621,57
20,9520,9621,91
30,9620,7821,74
4121,1222,12
50,8922,2123,1
60,9623,9624,92
71,0325,426,43
81,0123,224,21
91,0222,6923,71
101,0223,924,92
AVERAGE0,97522,48823,463



NUMBERCREATEDELETETOTAL
Chrome JS
10,230,030,26
20,280,040,32
30,280,030,31
40,270,030,3
50,260,030,29
60,280,040,32
70,270,040,31
80,290,030,32
90,290,030,32
100,270,040,31
AVERAGE0,2720,0340,306
Firefox JS
10,230,20,43
20,210,20,41
30,210,20,41
40,210,20,41
50,210,20,41
60,210,20,41
70,210,20,41
80,210,20,41
90,210,20,41
100,210,20,41
AVERAGE0,2120,20,412
IE JS
10,9345,846,73
20,9846,1947,17
30,9846,2947,27
40,9745,9246,89
50,9845,8246,8
60,9746,2947,26
70,9648,1549,11
81,0547,7548,8
90,9645,8546,81
100,9847,0248
AVERAGE0,97646,50847,484

The conclusions are weird this time:

  • The code converted from Dart to JS is lot of times slower than the JS, instead  in Internet Explorer that is 50% faster.
  • Firefox has the same problem with the converted code that had in the previous post.
  • Chrome is the faster in all the cases.
  • Creating things in the DOM is faster than deleting them, instead in Chrome and Firefox with JS.