Skip to content

Commit 986bcf2

Browse files
authored
fix: ci is not checking out submodule version but using the must recent version. Bypassing the audit. And better pr ci (#12)
* fix: ci is not checking out submodule version but using the must recent version. Bypassing the audit * feat: don't run database upload in PR's and forks to make it easier to test a build * fix: discover submodule json format * fix: ci using wrong matrix variables * fix: ci * chore: ci rename matrix subvariable to submodules * chore: ci * chore: ci name * chore: ci cleanup
1 parent 44771ee commit 986bcf2

File tree

3 files changed

+29
-103
lines changed

3 files changed

+29
-103
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ name: CI
33
on:
44
pull_request:
55
types:
6-
- closed
6+
- opened
7+
- synchronize
8+
- reopened
79
push:
810
branches:
911
- main
@@ -12,13 +14,12 @@ on:
1214
jobs:
1315
prepare:
1416
runs-on: ubuntu-latest
15-
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
1617

1718
outputs:
1819
submodule-matrix: ${{ steps.discover-submodules.outputs.submodule-matrix }}
1920
steps:
2021
- name: Checkout repository
21-
uses: actions/checkout@v2
22+
uses: actions/checkout@v4
2223
with:
2324
submodules: recursive
2425
persist-credentials: true
@@ -42,6 +43,7 @@ jobs:
4243
echo "submodule-matrix=$(cat submodules.json)" >> $GITHUB_OUTPUT
4344
4445
- name: Commit Metadata
46+
if: github.event_name != 'pull_request' && github.event.repository.fork == false
4547
run: |
4648
git config --global user.name 'github-actions[bot]'
4749
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
@@ -62,13 +64,14 @@ jobs:
6264
runs-on: ubuntu-latest
6365
strategy:
6466
fail-fast: false
65-
matrix:
66-
repository: ${{ fromJson(needs.prepare.outputs.submodule-matrix) }}
67+
matrix: ${{ fromJson(needs.prepare.outputs.submodule-matrix) }}
68+
name: Build (${{ matrix.submodules.repository }})
6769
steps:
6870
- name: Checkout Repository
6971
uses: actions/checkout@v4
7072
with:
71-
repository: ${{ matrix.repository }}
73+
repository: ${{ matrix.submodules.repository }}
74+
ref: ${{ matrix.submodules.sha }}
7275
token: ${{ secrets.GITHUB_TOKEN }}
7376
fetch-depth: 0
7477
submodules: recursive
@@ -78,7 +81,15 @@ jobs:
7881
with:
7982
node-version: '20'
8083

84+
- name: Run Database code
85+
if: github.event_name != 'pull_request' && github.event.repository.fork == false
86+
env:
87+
UPLOAD_TO_DATABASE: true
88+
run:
89+
echo "Running database code"
90+
8191
- name: Install Database SDK
92+
if: env.UPLOAD_TO_DATABASE
8293
run: |
8394
sudo apt-get update
8495
sudo apt-get install apt-transport-https ca-certificates gnupg curl
@@ -87,6 +98,7 @@ jobs:
8798
sudo apt-get update && sudo apt-get install google-cloud-cli
8899
89100
- name: Authenticate to Database
101+
if: env.UPLOAD_TO_DATABASE
90102
env:
91103
GCP_SERVICE_ACCOUNT_KEY: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
92104
run: |
@@ -111,6 +123,8 @@ jobs:
111123

112124
- name: Prepare Distribution Files
113125
id: prepare-distribution
126+
env:
127+
UPLOAD_TO_DATABASE: ${{ env.UPLOAD_TO_DATABASE }}
114128
run: |
115129
116130
mkdir -p dist
@@ -146,7 +160,7 @@ jobs:
146160
id=$(jq -r '.id' dist/metadata.json)
147161
148162
# Get repository name from the matrix
149-
REPOSITORY_NAME=$(echo ${{ matrix.repository }} | cut -d'/' -f2)
163+
REPOSITORY_NAME=$(echo ${{ matrix.submodules.repository }} | cut -d'/' -f2)
150164
echo "id=$REPOSITORY_NAME" >> $GITHUB_OUTPUT
151165
152166
cd dist
@@ -155,9 +169,11 @@ jobs:
155169
156170
echo "::debug::Successfully built plugin."
157171
158-
echo "::debug::Uploading plugin to database..."
159-
gsutil cp "$REPOSITORY_NAME.zip" gs://millennium-d9ce0.appspot.com/plugins/"$id.zip"
160-
echo "::debug::Successfully uploaded plugin to database."
172+
if [ "${UPLOAD_TO_DATABASE}" = "true" ]; then
173+
echo "::debug::Uploading plugin to database..."
174+
gsutil cp "$REPOSITORY_NAME.zip" gs://millennium-d9ce0.appspot.com/plugins/"$id.zip"
175+
echo "::debug::Successfully uploaded plugin to database."
176+
fi
161177
162178
- name: Upload Plugin Artifact
163179
uses: actions/upload-artifact@v4

.github/workflows/pr.yml

Lines changed: 0 additions & 90 deletions
This file was deleted.

scripts/discover-submodules.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
const { execSync } = require('child_process');
2-
let json = [];
2+
let json = {submodules: []};
33

44
try {
55
const submodules = execSync('git submodule').toString().split('\n').filter(Boolean);
66

77
submodules.forEach((line) => {
8-
const [, , name] = line.split(' ');
8+
const [, sha, name] = line.split(' ');
99
const url = execSync(`git config --get submodule.${name}.url`).toString().trim();
1010

1111
const owner = url.replace(/https:\/\/github.com\/([^\/]+)\/.*/, '$1');
1212
const repo = url.replace(/https:\/\/github.com\/[^\/]+\/([^\/]+).*/, '$1').replace(/\.git$/, '');
1313

14-
json.push(`${owner}/${repo}`);
14+
json.submodules.push({repository: `${owner}/${repo}`, sha: sha});
1515
});
1616
}
1717
catch (error) {

0 commit comments

Comments
 (0)