Skip to content

Commit b1f9de6

Browse files
committed
Bump to 1.4.2
1 parent a75ca49 commit b1f9de6

File tree

13 files changed

+232
-52
lines changed

13 files changed

+232
-52
lines changed

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@ All notable changes to this project will be documented in this file.
77
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

10+
## [1.4.2] - 2025-03-07
11+
12+
### Added
13+
14+
- Content placements to add to storage (no support of containered runs at this moment).
15+
- Support of crates inside workspaces (content example - `rust-crate-ver.py`; to know crate version of the package inside some workspace, just specify package's `Cargo.toml` path; works only with no `{ workspace = true }` versions).
16+
17+
### Fixed
18+
19+
- `auto_version_rule` deserialization from YAML/TOML (see the `MIGRATIONS.md`).
20+
1021
## [1.4.1] - 2025-03-05
1122

12-
### Changed
23+
### Added
1324

14-
- Added support of `daemon_wait_seconds` field in `CustomCommand`.
25+
- Support of `daemon_wait_seconds` field in `CustomCommand`.
1526

1627
## [1.4.0-beta-7] - 2025-02-20
1728

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "deployer"
3-
version = "1.4.1"
3+
version = "1.4.2"
44
edition = "2024"
55

66
[dependencies]

DOCS.en.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,44 @@ Time after time, you will start to notice that some projects are overused in oth
386386
"type": "add_to_storage",
387387
"short_name": "my-project",
388388
"auto_version_rule": {
389-
"plain_file": "file-with-current-version.txt"
389+
"type": "plain_file",
390+
"path": "file-with-current-version.txt"
390391
}
391392
}
392393
}
393394
```
394395

395396
- `short_name` - string designation of the content, which will be used to place it in the storage and each time it is used
396-
- `auto_version_rule` - a way to automatically determine the version of the content (either `plain_file` - a file that will contain only the version and nothing else, or `cmd_stdout` - a command that will display only the version and nothing else)
397+
- `auto_version_rule` - a way to automatically determine the version of the content (either `plain_file` with `path` field - a file that will contain only the version and nothing else, or `cmd_stdout` with `cmd` field - a command that will display only the version and nothing else)
398+
- `content` - you may not specify it in case when you need to push all your artifacts in the storage, or you can write this way:
399+
400+
```json
401+
{
402+
"title": "Add content",
403+
"desc": "",
404+
"info": "content-add@0.1.0",
405+
"tags": [],
406+
"action": {
407+
"type": "add_to_storage",
408+
"short_name": "my-project",
409+
"auto_version_rule": {
410+
"type": "plain_file",
411+
"path": "file-with-current-version.txt"
412+
},
413+
"content": {
414+
"type": "fixed_files",
415+
"placements": [
416+
{
417+
"from": "target/release/my-project",
418+
"to": "my-project"
419+
}
420+
]
421+
}
422+
}
423+
}
424+
```
425+
426+
In this example you may see that you can specify only needed to you files from Deployer's run directory (relative `from` path) to push at content's folder (relative `to` path).
397427

398428
However, sometimes the file needs to be edited in some way - and not so much even the added content from the Deployer repository, but, for example, various files in the build dependencies, e.g. manually forking Python libraries to add the desired functionality, etc., etc. And, as a rule, you want to do it without creating forks and synchronizing changes with the main repository! You can't do it with `git` patches alone.
399429

DOCS.ru.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,44 @@ deployer new content
386386
"type": "add_to_storage",
387387
"short_name": "my-project",
388388
"auto_version_rule": {
389-
"plain_file": "file-with-current-version.txt"
389+
"type": "plain_file",
390+
"path": "file-with-current-version.txt"
390391
}
391392
}
392393
}
393394
```
394395

395396
- `short_name` - строковое обозначение контента, которое будет использовано для размещения в хранилище и каждый раз при использовании
396-
- `auto_version_rule` - способ автоматического определения версии контента (либо `plain_file` - файл, в котором будет указана только версия и больше ничего, либо `cmd_stdout` - команда, которая выведет на экран только версию и больше ничего)
397+
- `auto_version_rule` - способ автоматического определения версии контента (либо `plain_file` с полем `path` - файл, в котором будет указана только версия и больше ничего, либо `cmd_stdout` c полем `cmd` - команда, которая выведет на экран только версию и больше ничего)
398+
- `content` - вы можете ничего не указывать в случае, если вам нужно поместить в хранилище все ваши артефакты, иначе вы можете написать следующим образом:
399+
400+
```json
401+
{
402+
"title": "Add content",
403+
"desc": "",
404+
"info": "content-add@0.1.0",
405+
"tags": [],
406+
"action": {
407+
"type": "add_to_storage",
408+
"short_name": "my-project",
409+
"auto_version_rule": {
410+
"type": "plain_file",
411+
"path": "file-with-current-version.txt"
412+
},
413+
"content": {
414+
"type": "fixed_files",
415+
"placements": [
416+
{
417+
"from": "target/release/my-project",
418+
"to": "my-project"
419+
}
420+
]
421+
}
422+
}
423+
}
424+
```
425+
426+
В этом примере видно, что вы можете указать только нужные вам файлы из папки запусков Деплойера (относительный путь `from`), чтобы поместить их в папку с контентом (относительный путь `to`).
397427

398428
Однако иногда файл нужно каким-то образом редактировать - и не столько даже добавляемый контент из хранилища Деплойера, сколько, например, различные файлы в зависимостях сборки, например, вручную делать форки библиотек Python для добавления нужной функциональности и т.д. и т.п. Причём, как правило, хочется делать это без создания форков и синхронизации изменений с `main`-репозиторием! Одними патчами `git`'а не обойтись.
399429

MIGRATIONS.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

33
> Actual configs' version: `4`.
44
5+
## From `1.4.1` to `1.4.2`
6+
7+
1. Manually check all your `add_to_storage` Actions (`AutoVersionExtractFromRule`): them now look like this:
8+
9+
```json
10+
[
11+
{
12+
"type": "add_to_storage",
13+
"short_name": "my-project",
14+
"auto_version_rule": {
15+
"type": "plain_file",
16+
"path": "file-with-current-version.txt"
17+
}
18+
},
19+
{
20+
"type": "add_to_storage",
21+
"short_name": "my-project-2",
22+
"auto_version_rule": {
23+
"type": "cmd_stdout",
24+
"cmd": <!-- {custom command} -->
25+
}
26+
}
27+
]
28+
```
29+
30+
Formally, you should now specify `type` field of `auto_version_rule` object.
31+
532
## From `1.4.0-beta-3` to `1.4.0-beta-4`
633

734
1. Manually check all your configuration files for programming languages and targets' OSes. Replace `null` values with strings in the lower register (for example, `"rust"`, `"linux"`, etc.).
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#!/usr/bin/env python
22

33
import tomllib
4+
import sys
45

5-
with open('Cargo.toml', 'rb') as f:
6-
data = tomllib.load(f)
7-
print(data['package']['version'])
6+
if len(sys.argv) == 1:
7+
with open('Cargo.toml', 'rb') as f:
8+
data = tomllib.load(f)
9+
print(data['package']['version'])
10+
else:
11+
with open(sys.argv[1], 'rb') as f:
12+
data = tomllib.load(f)
13+
print(data['package']['version'])

src/actions/storage_add.rs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
use serde::{Deserialize, Serialize};
77
use std::io::Read;
88

9+
use crate::configs::Placement;
910
use crate::entities::auto_version::AutoVersionExtractFromRule;
1011
use crate::entities::environment::RunEnvironment;
1112
use crate::entities::info::ContentInfo;
1213
use crate::entities::traits::Execute;
13-
use crate::storage::add_to_storage;
14+
use crate::storage::{add_single_to_storage, add_to_storage};
1415

1516
/// AddToStorage Action.
1617
#[derive(Deserialize, Serialize, PartialEq, Clone)]
@@ -19,40 +20,62 @@ pub struct AddToStorageAction {
1920
pub short_name: String,
2021
/// Automatic rule to extract version from project.
2122
pub auto_version_rule: AutoVersionExtractFromRule,
23+
/// What to put in the storage?
24+
pub content: Option<PutContentRule>,
25+
}
26+
27+
#[derive(Deserialize, Serialize, PartialEq, Clone)]
28+
#[serde(tag = "type", rename_all = "snake_case")]
29+
pub enum PutContentRule {
30+
Artifacts,
31+
FixedFiles { placements: Vec<Placement> },
2232
}
2333

2434
impl Execute for AddToStorageAction {
2535
/// Adds content to storage from given run environment.
2636
fn execute(&self, env: &RunEnvironment) -> anyhow::Result<(bool, Vec<String>)> {
27-
Ok(match &self.auto_version_rule {
28-
AutoVersionExtractFromRule::CmdStdout(cmd) => {
37+
let version = match &self.auto_version_rule {
38+
AutoVersionExtractFromRule::CmdStdout { cmd } => {
2939
let (succ, out) = cmd.execute(env)?;
3040
if !succ || out.is_empty() {
31-
(false, out)
32-
} else {
33-
let version = out.last().unwrap().trim().replace(">>> ", "");
34-
let info = ContentInfo::new(self.short_name.as_str(), version.as_str())?;
35-
if let Err(e) = add_to_storage(env.storage_dir, env.artifacts_dir, &info) {
36-
(false, vec![e.to_string()])
37-
} else {
38-
(true, vec![])
39-
}
41+
return Ok((false, out));
4042
}
43+
out.last().unwrap().trim().replace(">>> ", "")
4144
}
42-
AutoVersionExtractFromRule::PlainFile(path) => {
45+
AutoVersionExtractFromRule::PlainFile { path } => {
4346
let mut file = std::fs::File::open(path)?;
4447
let version = {
4548
let mut ver = String::new();
4649
file.read_to_string(&mut ver)?;
4750
ver.trim().to_string()
4851
};
49-
let info = ContentInfo::new(self.short_name.as_str(), version.as_str())?;
52+
version
53+
}
54+
};
55+
56+
let info = ContentInfo::new(self.short_name.as_str(), version.as_str())?;
57+
58+
Ok(match &self.content {
59+
Some(PutContentRule::Artifacts) | None => {
5060
if let Err(e) = add_to_storage(env.storage_dir, env.artifacts_dir, &info) {
5161
(false, vec![e.to_string()])
5262
} else {
5363
(true, vec![])
5464
}
5565
}
66+
Some(PutContentRule::FixedFiles { placements }) => {
67+
for placement in placements {
68+
if let Err(e) = add_single_to_storage(
69+
env.storage_dir,
70+
&env.run_dir.join(&placement.from),
71+
&placement.to,
72+
&info,
73+
) {
74+
return Ok((false, vec![e.to_string()]));
75+
}
76+
}
77+
(true, vec![])
78+
}
5679
})
5780
}
5881
}

src/configs/migrate.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ use crate::actions::buildlike::{BuildAction, PostBuildAction, PreBuildAction};
66
use crate::actions::deploylike::{ConfigureDeployAction, DeployAction, PostDeployAction};
77
use crate::actions::observe::ObserveAction;
88
use crate::actions::packlike::{DeliveryAction, InstallAction, PackAction};
9+
use crate::actions::storage_add::AddToStorageAction;
910
use crate::actions::test::TestAction;
1011
use crate::actions::{Action, DescribedAction};
1112
use crate::configs::migrations::project_config_v2_to_v3_migrations::*;
1213
use crate::configs::migrations::project_config_v3_to_v4_migrations::*;
1314
use crate::configs::{DeployerGlobalConfig, DeployerProjectOptions};
15+
use crate::entities::auto_version::AutoVersionExtractFromRule;
1416
use crate::entities::custom_command::{CustomCommand, Replacement, ReplacementGroup};
1517
use crate::entities::programming_languages::ProgrammingLanguage;
1618
use crate::entities::requirements::Requirement;
@@ -119,7 +121,18 @@ fn migrate_var_v3_to_v4(prev_var: &VariableV3) -> Variable {
119121
fn migrate_action_v3_to_v4(action: &DescribedActionV3) -> DescribedAction {
120122
DescribedAction {
121123
action: match &action.action {
122-
ActionV3::AddToStorage(a) => Action::AddToStorage(a.to_owned()),
124+
ActionV3::AddToStorage(a) => Action::AddToStorage(AddToStorageAction {
125+
short_name: a.short_name.to_owned(),
126+
auto_version_rule: match &a.auto_version_rule {
127+
AutoVersionExtractFromRuleV3::CmdStdout(cmd) => AutoVersionExtractFromRule::CmdStdout {
128+
cmd: migrate_custom_v3_to_v4(cmd),
129+
},
130+
AutoVersionExtractFromRuleV3::PlainFile(plain) => {
131+
AutoVersionExtractFromRule::PlainFile { path: plain.to_owned() }
132+
}
133+
},
134+
content: None,
135+
}),
123136
ActionV3::Build(b) => Action::Build(BuildAction {
124137
supported_langs: {
125138
let mut langs = vec![];

src/configs/migrations.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) mod project_config_v2_to_v3_migrations {
77
use std::path::PathBuf;
88

99
use super::project_config_v3_to_v4_migrations::*;
10-
use crate::actions::{patch::PatchAction, storage_add::AddToStorageAction};
10+
use crate::actions::patch::PatchAction;
1111
use crate::entities::{
1212
info::{ActionInfo, ContentInfo, Info, PipelineInfo, ShortName, info2str, str2info, str2info_wl},
1313
remote_host::RemoteHost,
@@ -100,7 +100,7 @@ pub(crate) mod project_config_v2_to_v3_migrations {
100100
Observe(ObserveActionV3),
101101
#[serde(serialize_with = "info2str", deserialize_with = "str2info_wl")]
102102
UseFromStorage(ContentInfo),
103-
AddToStorage(AddToStorageAction),
103+
AddToStorage(AddToStorageActionV3),
104104
Patch(PatchAction),
105105
}
106106

@@ -141,7 +141,7 @@ pub(crate) mod project_config_v3_to_v4_migrations {
141141
use std::collections::{HashMap, HashSet};
142142
use std::path::PathBuf;
143143

144-
use crate::actions::{patch::PatchAction, storage_add::AddToStorageAction};
144+
use crate::actions::patch::PatchAction;
145145
use crate::entities::{
146146
containered_opts::ContaineredOpts,
147147
info::{ActionInfo, ContentInfo, Info, PipelineInfo, ShortName, info2str, str2info, str2info_wl},
@@ -274,7 +274,7 @@ pub(crate) mod project_config_v3_to_v4_migrations {
274274
#[serde(serialize_with = "info2str", deserialize_with = "str2info_wl")]
275275
content_info: ContentInfo,
276276
},
277-
AddToStorage(AddToStorageAction),
277+
AddToStorage(AddToStorageActionV3),
278278
Patch(PatchAction),
279279
SubPipeline(Box<DescribedPipelineV3>),
280280
}
@@ -355,6 +355,19 @@ pub(crate) mod project_config_v3_to_v4_migrations {
355355
pub command: CustomCommandV3,
356356
}
357357

358+
#[derive(Deserialize, Serialize, PartialEq, Clone)]
359+
pub struct AddToStorageActionV3 {
360+
pub short_name: String,
361+
pub auto_version_rule: AutoVersionExtractFromRuleV3,
362+
}
363+
364+
#[derive(Deserialize, Serialize, PartialEq, Clone)]
365+
#[serde(rename_all = "snake_case")]
366+
pub enum AutoVersionExtractFromRuleV3 {
367+
CmdStdout(CustomCommandV3),
368+
PlainFile(PathBuf),
369+
}
370+
358371
#[derive(Deserialize, Serialize, PartialEq, Eq, Hash, Clone)]
359372
pub struct CustomCommandV3 {
360373
pub bash_c: String,

src/entities/auto_version.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ use crate::i18n;
88

99
/// Rule to extract version from the project automatically.
1010
#[derive(Deserialize, Serialize, PartialEq, Clone)]
11-
#[serde(rename_all = "snake_case")]
11+
#[serde(tag = "type", rename_all = "snake_case")]
1212
pub enum AutoVersionExtractFromRule {
1313
/// Extract from `stdout` of command.
14-
CmdStdout(CustomCommand),
14+
CmdStdout { cmd: CustomCommand },
1515
/// Extract from plain file.
16-
PlainFile(PathBuf),
16+
PlainFile { path: PathBuf },
1717
}
1818

1919
impl AutoVersionExtractFromRule {
2020
/// Returns rule type as `&str`.
2121
pub fn type_str(&self) -> &str {
2222
match self {
23-
Self::CmdStdout(_) => i18n::AUTO_VER_CMD_STDOUT,
24-
Self::PlainFile(_) => i18n::AUTO_VER_PLAIN_FILE,
23+
Self::CmdStdout { cmd: _ } => i18n::AUTO_VER_CMD_STDOUT,
24+
Self::PlainFile { path: _ } => i18n::AUTO_VER_PLAIN_FILE,
2525
}
2626
}
2727
}

0 commit comments

Comments
 (0)