Example CI #1384
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow contains checks for the examples in the `example` directory | |
# of the package. | |
name: Example CI | |
# Trigger the workflow whenever commits are pushed to any branch and modify | |
# source files, tests or configuration files. | |
# The workflow also runs when it is modified itself or source files outside of | |
# the `example` directory change because the examples depend on the `toml` | |
# package. However, source files of the `toml` package for tests can be ignored. | |
# | |
# Additionally, the workflow runs once every day at 6am on the `main` branch. | |
on: | |
push: | |
paths: | |
- ".github/workflows/example.yaml" | |
- "lib/**" | |
- "tool/*example*.sh" | |
- "example/**" | |
- "*.yaml" | |
schedule: | |
- cron: "0 6 * * *" | |
jobs: | |
# Analyzes the Dart code of the examples (i.e., all `.dart` files in the | |
# `lib`, `bin` and `test` sub-directories of the example packages in the | |
# `example` directory) with `dart analyze` or `flutter analyze`. | |
analyze-examples: | |
name: Analyze Code of Examples | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4.1.7 | |
- name: Setup Dart SDK | |
uses: dart-lang/setup-dart@v1.4 | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- name: Print Dart SDK Version | |
run: dart --version | |
- name: Print Flutter SDK Version | |
run: flutter --version | |
- name: Install Dependencies of Examples | |
run: ./tool/get-example-dependencies.sh | |
- name: Analyze Code of Examples | |
run: ./tool/analyze-examples.sh --fatal-infos | |
# Tests whether all Dart source files of the package i.e., all `.dart` files | |
# in the `lib`, `bin` and `test` directories) are formatted correctly with | |
# `dart format`. The `example`s are not analyzed by this job. | |
format-examples: | |
name: Check Code Formatting of Examples | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4.1.7 | |
- name: Setup Dart SDK | |
uses: dart-lang/setup-dart@v1.4 | |
- name: Print Dart SDK Version | |
run: dart --version | |
- name: Install Dependencies of Examples | |
run: ./tool/get-example-dependencies.sh | |
- name: Check Code Formatting of Examples | |
run: "./tool/format-examples.sh --show all | |
--output none | |
--set-exit-if-changed" | |
# Runs the `tool/test.sh` scripts of the `example`s. | |
test-examples: | |
name: Test Examples | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4.1.7 | |
- name: Setup Dart SDK | |
uses: dart-lang/setup-dart@v1.4 | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- name: Print Dart SDK Version | |
run: dart --version | |
- name: Install Dependencies of Examples | |
run: ./tool/get-example-dependencies.sh | |
- name: Run Tests of Examples | |
run: ./tool/test-examples.sh | |
# Runs the `tool/test_web.dart` scripts of the `example`s. | |
test-web-examples: | |
name: Test Web Examples | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4.1.7 | |
- name: Setup Dart SDK | |
uses: dart-lang/setup-dart@v1.4 | |
- name: Print Dart SDK Version | |
run: dart --version | |
- name: Add Executables Installed by Pub to PATH | |
run: echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH | |
- name: Install webdev | |
run: dart pub global activate webdev | |
- name: Build Web Examples | |
run: ./tool/build-web-examples.sh | |
- name: Set DISPLAY Environment Variable. | |
run: echo "DISPLAY=:99" >> $GITHUB_ENV | |
- name: Start X Virtual Framebuffer | |
run: sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & | |
- name: Start WebDriver | |
run: chromedriver --port=4444 --url-base=/wd/hub & | |
- name: Wait for WebDriver | |
run: while ! nc -z localhost 4444; do sleep 0.1; done | |
- name: Run Tests of Web Examples | |
run: ./tool/test-web-examples.sh | |
# Builds the Docker image for the `toml_to_json` example and pushes it to | |
# DockerHub. | |
build-and-push-toml-to-json-docker-image: | |
name: Build and Push `toml_to_json` Docker Image | |
runs-on: ubuntu-latest | |
needs: | |
- analyze-examples | |
- format-examples | |
- test-examples | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and Push | |
uses: docker/build-push-action@v6 | |
with: | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/toml-to-json:latest | |
file: example/toml_to_json/Dockerfile |