Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 23b2435

Browse files
committedMar 4, 2022
added notes about github workflow env variables
1 parent e5d443c commit 23b2435

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed
 

‎.github/workflows/ci.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- run: mkdocs gh-deploy --force
3333

3434
# Run language tracker
35-
- env:
35+
- name: Run language tracker
36+
env:
3637
ACCESS_TOKEN: "${{ secrets.ACCESS_TOKEN }}"
3738
run: python3 ${GITHUB_WORKSPACE}/scripts/lang-tracker.py

‎docs/dev/github.md

+28
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ To use the runner, add in your `.github/workflows/WORFLOW_NAME.yml` file:
9494
runs-on: self-hosted
9595
```
9696
97+
### Define a workflow
98+
99+
#### Generic env variables
100+
101+
* `${GITHUB_WORKSPACE}`: the project root folder (i.e. the one containing the `.github\workflows` subfolder)
102+
* `${{ github.event.repository.name }}`: the project name, in our case `the-notebook`
103+
* `${{ github.repository_owner }}`: the repository owner, in our case `sannae` (i.e. myself!)
104+
105+
106+
#### Use the secrets as env variables
107+
108+
Once you've defined a GitHub Secret, you can access it in your workflow as an environment variable from the step/job/workflow scope:
109+
110+
```yaml
111+
- name: Your step name
112+
113+
# Define an environment variable ACCESS_TOKEN
114+
# whose value is read from the GitHub Secret with the same name
115+
env:
116+
ACCESS_TOKEN: "${{ secrets.ACCESS_TOKEN }}"
117+
run: python3 ${GITHUB_WORKSPACE}/scripts/lang-tracker.py
118+
```
119+
120+
In the example above, the script `lang-tracker.py` is able to see the environment variable with the `os.environ[]` function:
121+
122+
```python
123+
g = Github(os.environ['ACCESS_TOKEN'])
124+
```
97125

98126

99127
## Github API

‎docs/index.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ The website configuration (including navigation, custom themes, extensions, plug
1919
Publishing is made on [GitHub Pages](https://pages.github.com/) and is handled by [GitHub Actions](https://github.com/features/actions) with a [cloud-hosted runner](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners).
2020

2121
The workflow YAML file is available [here](https://github.com/sannae/the-notebook/blob/main/.github/workflows/ci.yaml) and is triggered by any push on the `main` branch.
22+
23+
## Similar brilliant projects
24+
25+
* [:material-github: javierobcn/Notas](https://www.javieranto.com/)

‎mkdocs.yml

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
# Project information
12
site_name: The Notebook
3+
site_url: https://sannae.github.io/the-notebook
4+
site_author: sannae
5+
site_description: Welcome to my online knowledge base!
26

37
# Nav bar
48
nav:
@@ -36,11 +40,19 @@ repo_url: https://github.com/sannae/the-notebook
3640
# Graphics
3741
theme:
3842
name: material
43+
custom_dir: overrides
3944
favicon: images/logo.png
45+
language: en
46+
47+
# Themes
48+
font:
49+
text: Roboto
50+
code: Roboto Mono
51+
52+
# Icons
4053
icon:
4154
repo: fontawesome/brands/git-alt
4255
logo: material/library
43-
# custom_dir: material
4456

4557
# Color theme
4658
palette:

‎scripts/lang-tracker.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ def get_secret(setting, secrets=secrets):
1515
g = Github(get_secret('ACCESS_TOKEN'))
1616
"""
1717

18-
print(os.environ['ACCESS_TOKEN'])
19-
2018
g = Github(os.environ['ACCESS_TOKEN'])
2119

2220
lang_dict = dict()
@@ -36,3 +34,6 @@ def get_secret(setting, secrets=secrets):
3634

3735
# output
3836
print(total_langs)
37+
38+
# Write record on SQLite database
39+

0 commit comments

Comments
 (0)
Please sign in to comment.