Skip to content

Commit 4cbb778

Browse files
committed
Make steps using SSH and GPG keys optional
Depending on their presence.
1 parent bb2f5bd commit 4cbb778

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

.github/workflows/build.yaml

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ env:
1212
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
1313
VCPKG_REPOSITORY: https://github.com/OpenMW/vcpkg.git
1414
VCPKG_REVISION: dbbbfe8f58195ba49f3141dbba7a4f4b35e92052
15-
GPG_KEY: 8D5838140D294CE3C17ED6AE31FC2142D139BD97
1615

1716
jobs:
1817
static:
@@ -136,33 +135,59 @@ jobs:
136135
path: ${{ github.workspace }}/vcpkg-x64-windows-${{ github.sha }}.7z
137136

138137
- name: Setup ssh-agent
138+
env:
139+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
140+
if: ${{ env.SSH_PRIVATE_KEY != '' }}
139141
uses: webfactory/ssh-agent@v0.9.0
140142
with:
141143
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
142144

143145
- name: Import GPG key
146+
id: import_gpg
147+
env:
148+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
149+
GPG_PRIVATE_KEY_PASSPHRASE: ${{ secrets.GPG_PRIVATE_KEY_PASSPHRASE }}
150+
if: ${{ env.GPG_PRIVATE_KEY != '' && env.GPG_PRIVATE_KEY_PASSPHRASE != '' }}
144151
uses: crazy-max/ghaction-import-gpg@v6
145152
with:
146153
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
147154
passphrase: ${{ secrets.GPG_PRIVATE_KEY_PASSPHRASE }}
148155

149156
- name: Configure ssh known hosts for gitlab.com
157+
env:
158+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
159+
if: ${{ env.SSH_PRIVATE_KEY != '' }}
150160
run: cat gitlab_known_hosts >> ~/.ssh/known_hosts
151161

152-
- name: Configure git
162+
- name: Configure git user
153163
run: |
154164
git config --global user.email 'openmw-deps-build@users.noreply.github.com'
155165
git config --global user.name 'openmw-deps-build'
156-
git config --global user.signkey ${{ env.GPG_KEY }}
166+
167+
- name: Configure git sign key
168+
if: ${{ steps.import_gpg.outputs.fingerprint != '' }}
169+
run: |
170+
git config --global user.signkey ${{ steps.import_gpg.outputs.fingerprint }}
157171
git config --global commit.gpgsign true
158172
159-
- name: Clone openmw-deps repository
173+
- name: Clone openmw-deps repository via SSH
160174
env:
175+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
161176
GIT_LFS_SKIP_SMUDGE: 1
162177
# see https://github.com/git-lfs/git-lfs/issues/5749
163178
GIT_CLONE_PROTECTION_ACTIVE: false
179+
if: ${{ env.SSH_PRIVATE_KEY != '' }}
164180
run: git clone git@gitlab.com:OpenMW/openmw-deps.git
165181

182+
- name: Clone openmw-deps repository via HTTPS
183+
env:
184+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
185+
GIT_LFS_SKIP_SMUDGE: 1
186+
# see https://github.com/git-lfs/git-lfs/issues/5749
187+
GIT_CLONE_PROTECTION_ACTIVE: false
188+
if: ${{ env.SSH_PRIVATE_KEY == '' }}
189+
run: git clone https://gitlab.com/OpenMW/openmw-deps.git
190+
166191
- name: Move exported vcpkg packages to openmw-deps repository
167192
run: mv vcpkg-x64-windows-${{ github.sha }}.7z openmw-deps/windows/
168193

@@ -184,9 +209,18 @@ jobs:
184209
git checkout -b vcpkg-x64-windows-${{ github.sha }}
185210
git add windows/vcpkg-x64-windows-${{ github.sha }}.7z
186211
git commit -F commit_message.txt
187-
git verify-commit HEAD
212+
213+
- name: Verify commit to openmw-deps repository
214+
if: ${{ steps.import_gpg.outputs.fingerprint != '' }}
215+
working-directory: ${{ github.workspace }}/openmw-deps
216+
run: git verify-commit HEAD
188217

189218
- name: Push exported vcpkg packages to gitlab
190-
if: github.ref == 'refs/heads/master'
219+
env:
220+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
221+
# Make sure only signed commits are pushed
222+
if: ${{ vars.PUSH_URL != '' && env.SSH_PRIVATE_KEY != '' && steps.import_gpg.outputs.fingerprint != '' }}
191223
working-directory: ${{ github.workspace }}/openmw-deps
192-
run: git push origin vcpkg-x64-windows-${{ github.sha }}
224+
run: |
225+
git remote set-url --push origin "${{ vars.PUSH_URL }}"
226+
git push origin vcpkg-x64-windows-${{ github.sha }}

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# openmw-deps-build
2+
3+
This is a repository to host CI jobs to build dependencies for OpenMW to be cached as binary artifacts at https://gitlab.com/OpenMW/openmw-deps.
4+
Jobs start automatically on push to master and automatically push archived artifacts to another git repository.
5+
6+
To make this work properly multiple [secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) have to be configured:
7+
8+
* `SSH_PRIVATE_KEY` with private SSH key allowed to push changes to repository specified via `PUSH_URL` variable (e.g. generated by `ssh-keygen`).
9+
* `GPG_PRIVATE_KEY` with private GPG key to sign commits with GPG signature (e.g. generated with `gpg --full-generate-key`).
10+
* `GPG_PRIVATE_KEY_PASSPHRASE` a passphrase for the `GPG_PRIVATE_KEY` to make it possible to use the GPG key (e.g. the value used during `gpg --full-generate-key`).
11+
12+
Also following [variables](https://docs.github.com/en/actions/learn-github-actions/variables) have to be set:
13+
14+
* `PUSH_URL` with target SSH-based URL for `git push` command (e.g. `git@gitlab.com:OpenMW/openmw-deps.git`).

0 commit comments

Comments
 (0)