Skip to main content

cargo_dist/config/v1/hosts/
github.rs

1//! github host
2
3use super::*;
4
5/// github host config (raw)
6#[derive(Debug, Default, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "kebab-case")]
8pub struct GithubHostLayer {
9    /// Common options
10    #[serde(flatten)]
11    pub common: CommonHostLayer,
12
13    /// Whether we should create the Github Release for you when you push a tag.
14    ///
15    /// If true (default), dist will create a new Github Release and generate
16    /// a title/body for it based on your changelog.
17    ///
18    /// If false, dist will assume a draft Github Release already exists
19    /// with the title/body you want. At the end of a successful publish it will
20    /// undraft the Github Release.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub create: Option<bool>,
23
24    /// Publish GitHub Releases to this repo instead of the current one
25    ///
26    /// The user must also set GH_RELEASES_TOKEN in their SECRETS
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub repo: Option<GithubRepoPair>,
29
30    /// If `repo` is used, the commit ref to used will
31    /// be read from the HEAD of the submodule at this path
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub submodule_path: Option<Utf8PathBuf>,
34
35    /// Which phase to create the github release in
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub during: Option<GithubReleasePhase>,
38
39    /// Whether GitHub Attestations is enabled (default false)
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub attestations: Option<bool>,
42
43    /// GitHub Attestation filters (default *)
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub attestations_filters: Option<GithubAttestationsFilters>,
46
47    /// When to generate GitHub Attestations (default build-local-artifacts)
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub attestations_phase: Option<GithubAttestationsPhase>,
50}
51/// github host config (final)
52#[derive(Debug, Default, Clone)]
53pub struct GithubHostConfig {
54    /// Common options
55    pub common: CommonHostConfig,
56    /// Whether we should create the Github Release for you
57    pub create: bool,
58    /// Publish GitHub Releases to this repo instead of the current one
59    pub repo: Option<GithubRepoPair>,
60    /// If github-releases-repo is used, the commit ref to used will
61    /// be read from the HEAD of the submodule at this path
62    pub submodule_path: Option<Utf8PathBuf>,
63    /// Which phase to create the github release in
64    pub during: GithubReleasePhase,
65    /// Whether GitHub Attestations is enabled (default false)
66    pub attestations: bool,
67    /// GitHub Attestation filters (default *)
68    pub attestations_filters: GithubAttestationsFilters,
69    /// When to generate GitHub Attestations (default build-local-artifacts)
70    pub attestations_phase: GithubAttestationsPhase,
71}
72
73impl GithubHostConfig {
74    /// Get defaults for the given package
75    pub fn defaults_for_workspace(_workspaces: &WorkspaceGraph, common: &CommonHostConfig) -> Self {
76        Self {
77            common: common.clone(),
78            create: true,
79            repo: None,
80            submodule_path: None,
81            during: GithubReleasePhase::default(),
82            attestations: false,
83            attestations_filters: GithubAttestationsFilters::default(),
84            attestations_phase: GithubAttestationsPhase::default(),
85        }
86    }
87}
88
89impl ApplyLayer for GithubHostConfig {
90    type Layer = GithubHostLayer;
91    fn apply_layer(
92        &mut self,
93        Self::Layer {
94            common,
95            create,
96            repo,
97            submodule_path,
98            during,
99            attestations,
100            attestations_filters,
101            attestations_phase,
102        }: Self::Layer,
103    ) {
104        self.common.apply_layer(common);
105        self.create.apply_val(create);
106        self.repo.apply_opt(repo);
107        self.submodule_path.apply_opt(submodule_path);
108        self.during.apply_val(during);
109        self.attestations.apply_val(attestations);
110        self.attestations_filters.apply_val(attestations_filters);
111        self.attestations_phase.apply_val(attestations_phase);
112    }
113}
114impl ApplyLayer for GithubHostLayer {
115    type Layer = GithubHostLayer;
116    fn apply_layer(
117        &mut self,
118        Self::Layer {
119            common,
120            create,
121            repo,
122            submodule_path,
123            during,
124            attestations,
125            attestations_filters,
126            attestations_phase,
127        }: Self::Layer,
128    ) {
129        self.common.apply_layer(common);
130        self.create.apply_opt(create);
131        self.repo.apply_opt(repo);
132        self.submodule_path.apply_opt(submodule_path);
133        self.during.apply_opt(during);
134        self.attestations.apply_opt(attestations);
135        self.attestations_filters.apply_opt(attestations_filters);
136        self.attestations_phase.apply_opt(attestations_phase);
137    }
138}
139
140impl std::ops::Deref for GithubHostConfig {
141    type Target = CommonHostConfig;
142    fn deref(&self) -> &Self::Target {
143        &self.common
144    }
145}