-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull image version from metadata file (#1599)
Closes #1554 ![image](https://github.com/user-attachments/assets/fa51c0a3-a25e-4112-8ef2-990404c746d6)
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
photon-core/src/main/java/org/photonvision/common/hardware/OsImageVersion.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* 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 | ||
* (at your option) 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 <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.common.hardware; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
import org.photonvision.common.logging.LogGroup; | ||
import org.photonvision.common.logging.Logger; | ||
|
||
/** | ||
* Our blessed images inject the current version via this build workflow: | ||
* https://github.com/PhotonVision/photon-image-modifier/blob/2e5ddb6b599df0be921c12c8dbe7b939ecd7f615/.github/workflows/main.yml#L67 | ||
* | ||
* <p>This class provides a convienent abstraction around this | ||
*/ | ||
public class OsImageVersion { | ||
private static final Logger logger = new Logger(OsImageVersion.class, LogGroup.General); | ||
|
||
private static Path imageVersionFile = Path.of("/opt/photonvision/image-version"); | ||
|
||
public static final Optional<String> IMAGE_VERSION = getImageVersion(); | ||
|
||
private static Optional<String> getImageVersion() { | ||
if (!imageVersionFile.toFile().exists()) { | ||
logger.warn( | ||
"Photon cannot locate base OS image version metadata at " + imageVersionFile.toString()); | ||
return Optional.empty(); | ||
} | ||
|
||
try { | ||
return Optional.of(Files.readString(imageVersionFile).strip()); | ||
} catch (IOException e) { | ||
logger.error("Couldn't read image-version file", e); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
} |
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