@@ -4,7 +4,7 @@ name: Python Package with caching
44
55# cancel any previous running or pending jobs from the same branch
66concurrency :
7- group : python-package-conda-cache-${{ github.head_ref }}
7+ group : python-package-conda-cache-${{ github.ref }}
88 cancel-in-progress : true
99
1010on :
2222 CACHE_NUMBER : 0 # increase to reset cache manually
2323
2424jobs :
25+
2526 build :
2627
28+ # do not run twice when push to a branch linked to a PR
2729 # https://github.com/orgs/community/discussions/57827
2830 if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
2931
30-
3132 strategy :
3233 matrix :
3334 include :
5253 - name : Set cache date
5354 run : echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
5455
55- - uses : actions/cache@v4
56+ - name : Use env cache
57+ uses : actions/cache@v4
5658 with :
5759 path : ${{ matrix.prefix }}
5860 key : ${{ matrix.label }}-conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
6567 - name : Run tests
6668 shell : bash -l {0}
6769 run : pytest ./tests
70+
71+
72+ # maybe split back into two workflows depending on each other
73+ build-docs :
74+ needs : build
75+
76+ strategy :
77+ matrix :
78+ include :
79+ - os : ubuntu-latest
80+ label : linux-64
81+ prefix : /usr/share/miniconda3/envs/my-env
82+
83+ name : ${{ matrix.label }}
84+ runs-on : ${{ matrix.os }}
85+ steps :
86+ - uses : actions/checkout@v4
87+
88+ - name : Setup Miniforge
89+ uses : conda-incubator/setup-miniconda@v2
90+ with :
91+ miniforge-version : latest
92+ activate-environment : my-env
93+
94+ - name : Set cache date
95+ run : echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
96+
97+ - name : Restore doc env cache
98+ uses : actions/cache@v4
99+ with :
100+ path : ${{ matrix.prefix }}
101+ key : ${{ matrix.label }}-conda-${{ hashFiles('environment.yml') }}-${{ hashFiles('docs/requirements.txt') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
102+ id : cache-doc
103+
104+ - name : Restore env cache
105+ if : steps.cache-doc.outputs.cache-hit != 'true'
106+ uses : actions/cache/restore@v4
107+ with :
108+ path : ${{ matrix.prefix }}
109+ key : ${{ matrix.label }}-conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
110+ fail-on-cache-miss : true
111+ id : cache
112+
113+ - name : Install documentation requirements
114+ if : steps.cache-doc.outputs.cache-hit != 'true'
115+ shell : bash -l {0}
116+ run : pip install -r docs/requirements.txt
117+
118+ - name : Save doc env cache
119+ if : steps.cache-doc.outputs.cache-hit != 'true'
120+ uses : actions/cache/save@v4
121+ with :
122+ path : ${{ matrix.prefix }}
123+ key : ${{ matrix.label }}-conda-${{ hashFiles('environment.yml') }}-${{ hashFiles('docs/requirements.txt') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
124+ id : cache-doc
125+
126+ - name : Build documentation src
127+ shell : bash -l {0}
128+ run : make build-src -C docs/
129+
130+ - name : Build HTML
131+ shell : bash -l {0}
132+ run : make html -C docs/
133+
134+ - name : Upload artifacts
135+ if : github.ref == 'refs/heads/master' && github.event_name == 'push'
136+ uses : actions/upload-pages-artifact@v3
137+ with :
138+ path : docs/build/html/
139+
140+ deploy :
141+ if : github.ref == 'refs/heads/master' && github.event_name == 'push'
142+ needs : build-docs
143+ runs-on : ubuntu-latest
144+
145+ environment :
146+ name : github-pages
147+
148+ permissions :
149+ pages : write
150+ id-token : write
151+
152+ steps :
153+ - name : Deploy
154+ uses : actions/deploy-pages@v4
155+ with :
156+ token : ${{ secrets.GITHUB_TOKEN }}
0 commit comments