Skip to content

A Spring Boot project that dynamically generates and updates weather forecasts using GitHub Actions, featuring hourly and multi-day forecast tables for easy embedding into GitHub profiles.

License

Notifications You must be signed in to change notification settings

MaarceloLuiz/springboot-weather-forecast

Repository files navigation

1- Hourly Forecast

Today's Weather

Dublin - 2025-02-09

Weather Condition Icon

Patchy rain nearby

Moon Phase Icon

Waxing Gibbous

Hour 00:0001:0002:0003:0004:0005:0006:0007:0008:0009:0010:0011:0012:0013:0014:0015:0016:0017:0018:0019:0020:0021:0022:0023:00
Weather Weather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition IconWeather Condition Icon
Condition Patchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPartly cloudyLight rain showerPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearbyPatchy rain nearby
Temperature 3.9 °C3.3 °C3.2 °C4.4 °C4.8 °C5.1 °C5.2 °C5.1 °C5.5 °C5.8 °C5.9 °C6.0 °C6.1 °C6.3 °C6.5 °C6.6 °C6.7 °C6.5 °C6.4 °C6.1 °C5.9 °C6.2 °C5.9 °C5.5 °C
Wind 11.5 kph12.2 kph14.0 kph15.5 kph18.0 kph19.8 kph21.6 kph22.0 kph22.0 kph23.4 kph22.3 kph23.4 kph25.2 kph24.1 kph23.8 kph23.4 kph23.8 kph23.8 kph24.5 kph25.6 kph24.5 kph23.8 kph24.5 kph24.5 kph

Updated at: 2025-02-09 07:11 by MaarceloLuiz/springboot-weather-forecast

2- Multi-Day Forecast

3 Days Weather Forecast

Dublin - 2025-02-09

Weather Condition Icon

Patchy rain nearby

Moon Phase Icon

Waxing Gibbous

Date 2025-02-092025-02-102025-02-11
Weather Weather Condition IconWeather Condition IconWeather Condition Icon
Condition Patchy rain nearbyPatchy rain nearbyPatchy rain nearby
Moon Phase Waxing GibbousWaxing GibbousWaxing Gibbous
Moon Moon Phase IconMoon Phase IconMoon Phase Icon
Temperature 3.2 - 6.7 °C3.6 - 5.0 °C3.9 - 5.4 °C
Wind 25.6 kph27.7 kph20.2 kph

Updated at: 2025-02-09 07:11 by MaarceloLuiz/springboot-weather-forecast


Weather Forecast

NPM

Objective

  • Fetching accurate weather data from WeatherAPI.
  • Updating forecasts automatically.
  • Using a CI/CD pipeline for workflow automation.

Features

  • Daily Updates: Automatically fetches and updates weather forecasts every day.
  • GitHub Actions: Utilizes workflows to automate daily operations.
  • Dockerized Environment: Provides a consistent runtime environment for builds and tests.
  • Java Spring Boot: Implements the application's backend logic.
  • Library Deployment with Repsy: WeatherAPI's library was deployed on Repsy, with the library also available on GitHub Packages.
  • Customizable Forecast: Configurable for location, days and table style.

Technologies and Frameworks

  • Programming Languages & Frameworks
    • Java
    • Spring Boot
    • Maven (Build Tool)
  • CI/CD & Automation
    • GitHub Actions
    • Workflow Configuration (action.yml)
  • Containerization
    • Docker

How to Use

Step 1: Create an Account and Get an API Key

  • Visit WeatherAPI and create a free account.
  • After signing up, navigate to your account dashboard.
  • Generate a new API key, which will be required for the application to fetch weather data.
  • Save this API key securely, as you’ll need it in the next steps.

Step 2: Embed the Tables in Any Repository

You can embed the generated tables into any repository, including your GitHub profile repository. Follow these steps:

  • If you haven’t already, create a repository named / (e.g., github.com/yourusername/yourusername). This will automatically act as your GitHub profile's README.md.
  • Insert the following placeholders into your README.md file exactly as shown below. Place the placeholders in the specific location where you want the table to appear.
<!-- HOURLY-START -->
<!-- HOURLY-END -->

<!-- MULTI-DAY-START -->
<!-- MULTI-DAY-END -->

These placeholders are required for the workflow to identify where to embed the forecast tables. Make sure the placeholders match exactly as shown above, including the casing and dashes.

  • <!-- HOURLY-START -->, <!-- HOURLY-END --> : These placeholders will embed the hourly table, in case you choose this option in the workflow configuration.
  • <!-- MULTI-DAY-START -->, <!-- MULTI-DAY-END --> : These placeholders will embed the multi-day table, in case you choose this option in the workflow configuration.

Why should you add both placeholders?

  • Flexibility: If you only choose one table type now, the other placeholder will simply remain empty and won't impact your workflow or file appearance.
  • Even if you only choose one table type (e.g., hourly), the workflow will ignore unused placeholders. You can later update the TABLE_TYPE variable to include other table types (e.g., multi-day or both) without modifying your README.md file.

Step 3: Set Up Environment Variables

Configuration and Environment Variables
To add Secrets and Variables:, follow these steps carefully:

  • Navigate to your repository on GitHub.
  • Go to Settings > Secrets and variables > Actions.
  • Under the Secrets tab, click New Repository Secret and add the following exactly as shown:
    • WEATHER_API_KEY: Your API key from WeatherAPI.
  • Under the Variables tab, click New Repository Variable and add the following variables exactly as shown:
    • FORECAST_CITY: The city for which you want the weather forecast (e.g., Dublin).
    • FORECAST_DAYS: Number of days to forecast (e.g., 3 for a 3-day forecast).
    • TABLE_TYPE: The type of forecast table. Choose ONE of the following options:

⚠️ Important: Ensure the variable names (WEATHER_API_KEY, FORECAST_CITY , FORECAST_DAYS, TABLE_TYPE ) are entered exactly as shown above, including capitalization.

Step 4: Set Up the GitHub Workflow

  • To create a folder in your repository called .github/workflows/. follow the instructions:
    • Navigate to the Actions tab in your repository.
    • Under "Simple workflow", click "Configure".
    • Rename the default workflow file to update-weather.yml or update-readme.yml for clarity.
  • Copy and paste the following workflow code into the file:
name: "Update Weather"

on:
  workflow_dispatch:
  schedule:
    - cron: "0 9 * * *" 
  
jobs:
  run-weather-app:
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      - name: Check out repository
        uses: actions/checkout@v3

      - name: Run Action
        uses: MaarceloLuiz/springboot-weather-forecast@v1.0.2
        with:
          WEATHER_API_KEY: ${{ secrets.WEATHER_API_KEY }}
          FORECAST_CITY: ${{ vars.FORECAST_CITY }}
          FORECAST_DAYS: ${{ vars.FORECAST_DAYS }}
          TABLE_TYPE: ${{ vars.TABLE_TYPE }}

      - name: Commit and Push Changes
        run: |
          git config --global user.name "github-actions"
          git config --global user.email "github-actions@github.com"
          git add README.md
          git commit -m "Update weather forecast" || echo "No changes to commit"
          git push origin main

Workflow Explanation:

  • cron: "0 9 * * *" -> Runs automatically every day at 9:00 AM UTC.
  • MaarceloLuiz/springboot-weather-forecast@v1.0.2 -> Executes the custom GitHub action that generates the weather forecast tables.
    • It uses the input you defined before:
      • WEATHER_API_KEY, FORECAST_CITY, FORECAST_DAYS, TABLE_TYPE.
  • Commit and Push Changes:
    • Stages the updated README.md file and commits the changes with the message: Update weather forecast.
    • Pushes the changes to the main branch of the repository and includes a fallback (|| echo "No changes to commit") in case there are no updates to the forecast tables.

Step 5: Ensure your Workflow has permission to push changes to your repository

  • Go to your repository settings:
    • Settings > Actions > General
  • Under Workflow permissions, select:
    • Read and write permissions
  • Click Save.

Step 6: Run the Workflow or Let it Run Automatically

  • Manually Run the Workflow:
    • Go to the Actions tab in your repository.
    • Find the "Update Weather" workflow in the list.
    • Click "Run workflow" to test it immediately.
  • Automatically Run the Workflow:
    • The workflow is set to run daily at 9:00 AM UTC based on the schedule defined in the cron configuration.
  • Check the Results:
    • Once the workflow completes, check your README.md file in the repository.

About

A Spring Boot project that dynamically generates and updates weather forecasts using GitHub Actions, featuring hourly and multi-day forecast tables for easy embedding into GitHub profiles.

Topics

Resources

License

Stars

Watchers

Forks

Packages