Updated at: 2025-02-09 07:11 by MaarceloLuiz/springboot-weather-forecast
Updated at: 2025-02-09 07:11 by MaarceloLuiz/springboot-weather-forecast
- Fetching accurate weather data from WeatherAPI.
- Updating forecasts automatically.
- Using a CI/CD pipeline for workflow automation.
- 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.
- Programming Languages & Frameworks
- Java
- Spring Boot
- Maven (Build Tool)
- CI/CD & Automation
- GitHub Actions
- Workflow Configuration (action.yml)
- Containerization
- Docker
- 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.
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.
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:hourly
: For hourly forecasts. -> hourly table examplemulti-day
: For multi-day forecasts. -> multi-day table exampleboth
: For both hourly and multi-day forecasts.
WEATHER_API_KEY
, FORECAST_CITY
, FORECAST_DAYS
, TABLE_TYPE
) are entered exactly as shown above, including capitalization.
- 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.
- It uses the input you defined before:
- 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.
- Go to your repository settings:
- Settings > Actions > General
- Under Workflow permissions, select:
- Read and write permissions
- Click Save.
- 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.