Skip to content

Commit

Permalink
feat: add add_github_token method on job and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Nov 11, 2024
1 parent 70bebf6 commit e55854a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
- name: Release Plz
uses: MarcoIeni/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 1 addition & 4 deletions workspace/gh-workflow-gen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ fn main() {
.permissions(Permissions::read())
.on(event)
.add_job("build", job)
.add_job(
"release",
release.add_env(("GITHUB_TOKEN", "${{ secrets.GH_TOKEN }}")),
)
.add_job("release", release.add_github_token())
.generate()
.unwrap();
}
12 changes: 12 additions & 0 deletions workspace/gh-workflow/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ impl Workflow {
self.env = Some(env);
self

Check warning on line 100 in workspace/gh-workflow/src/workflow.rs

View workflow job for this annotation

GitHub Actions / Build and Test

Diff in /home/runner/work/rust-gh-workflow/rust-gh-workflow/workspace/gh-workflow/src/workflow.rs
}

/// Add the default token created by GitHub to authenticate on behalf of GitHub Actions.
/// See: <https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication>
pub fn add_github_token(self) -> Self {
self.add_env(("GITHUB_TOKEN", "${{ secrets.GITHUB_TOKEN }}"))
}
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -191,6 +197,12 @@ impl Job {
self.env = Some(env);
self

Check warning on line 198 in workspace/gh-workflow/src/workflow.rs

View workflow job for this annotation

GitHub Actions / Build and Test

Diff in /home/runner/work/rust-gh-workflow/rust-gh-workflow/workspace/gh-workflow/src/workflow.rs
}

/// Add the default token created by GitHub to authenticate on behalf of GitHub Actions.
/// See: <https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication>
pub fn add_github_token(self) -> Self {
self.add_env(("GITHUB_TOKEN", "${{ secrets.GITHUB_TOKEN }}"))
}
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
Expand Down

0 comments on commit e55854a

Please sign in to comment.