#!/usr/bin/env bash # Copyright (C) 2023 WYATT GROUP # Please see the AUTHORS file for details. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . basename=$(basename "$0") basepath=$(dirname "$0") # Check for arguments, first argument should be wyatt_analysis_version. if [ $# -eq 0 ]; then echo "Usage: $basename " exit 1 fi wyatt_analysis_version=$1 # Check for dependencies. if ! command -v yq &>/dev/null; then echo "yq could not be found. Please install it and try again." echo "https://github.com/mikefarah/yq" exit 1 fi # Read latest version latest_version=$(yq eval '.version' "${basepath}/../pubspec.yaml") echo "> latest package version is: $latest_version" echo "> new package version is: $wyatt_analysis_version" # Create array with all files that need to exist files=( "${basepath}/../pubspec.yaml" "${basepath}/../README.md" "${basepath}/../lib/wyatt_analysis.dart" "${basepath}/../lib/analysis_options.yaml" "${basepath}/../lib/analysis_options.flutter.yaml" "${basepath}/../lib/analysis_options.${latest_version}.yaml" "${basepath}/../lib/analysis_options.flutter.${latest_version}.yaml" ) # Check if all files exist for file in "${files[@]}"; do if [ ! -f "$file" ]; then echo "File ${file} doesn't exists" exit 1 fi done # Create new analysis_options files echo "Creating new analysis_options files" cp "${basepath}/../lib/analysis_options.${latest_version}.yaml" "${basepath}/../lib/analysis_options.${wyatt_analysis_version}.yaml" cp "${basepath}/../lib/analysis_options.flutter.${latest_version}.yaml" "${basepath}/../lib/analysis_options.flutter.${wyatt_analysis_version}.yaml" # Update version in new analysis_options files echo "Updating version in new analysis_options files" sed -i.bu "s/${latest_version}/${wyatt_analysis_version}/g" "${basepath}/../lib/analysis_options.${wyatt_analysis_version}.yaml" rm "${basepath}/../lib/analysis_options.${wyatt_analysis_version}.yaml.bu" sed -i.bu "s/${latest_version}/${wyatt_analysis_version}/g" "${basepath}/../lib/analysis_options.flutter.${wyatt_analysis_version}.yaml" rm "${basepath}/../lib/analysis_options.flutter.${wyatt_analysis_version}.yaml.bu" # Update version in pubspec.yaml echo "Updating version in pubspec.yaml" sed -i.bu "s/${latest_version}/${wyatt_analysis_version}/g" "${basepath}/../pubspec.yaml" rm "${basepath}/../pubspec.yaml.bu" # Update version in README.md echo "Updating version in README.md" sed -i.bu "s/${latest_version}/${wyatt_analysis_version}/g" "${basepath}/../README.md" rm "${basepath}/../README.md.bu" # Update version in wyatt_analysis.dart echo "Updating version in wyatt_analysis.dart" sed -i.bu "s/${latest_version}/${wyatt_analysis_version}/g" "${basepath}/../lib/wyatt_analysis.dart" rm "${basepath}/../lib/wyatt_analysis.dart.bu" # Update version in analysis_options.yaml echo "Updating version in analysis_options.yaml" sed -i.bu "s/${latest_version}/${wyatt_analysis_version}/g" "${basepath}/../lib/analysis_options.yaml" rm "${basepath}/../lib/analysis_options.yaml.bu" # Update version in analysis_options.flutter.yaml echo "Updating version in analysis_options.flutter.yaml" sed -i.bu "s/${latest_version}/${wyatt_analysis_version}/g" "${basepath}/../lib/analysis_options.flutter.yaml" rm "${basepath}/../lib/analysis_options.flutter.yaml.bu" exit 0