Skip to content

Commit 3126366

Browse files
authored
Merge pull request #170 from microsoft/dilan/publish-opensource-packs
Publish Public Packs
2 parents 0544343 + b112947 commit 3126366

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Microsoft CodeQL Pack Publish
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
check-branch:
8+
if: github.ref != 'refs/heads/main'
9+
runs-on: ubuntu-latest
10+
steps:
11+
- run: echo "This workflow can only run on the 'main' branch." && exit 1
12+
codeqlversion:
13+
needs: check-branch
14+
runs-on: ubuntu-latest
15+
outputs:
16+
codeql_version: ${{ steps.set_codeql_version.outputs.codeql_version }}
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- name: Set CodeQL Version
23+
id: set_codeql_version
24+
run: |
25+
git fetch
26+
git fetch --tags
27+
CURRENT_COMMIT=$(git rev-list -1 HEAD)
28+
CURRENT_TAG=$(git describe --tags --abbrev=0 --match 'codeql-cli/v*' $CURRENT_COMMIT)
29+
CODEQL_VERSION="${CURRENT_TAG#codeql-cli/}"
30+
echo "CODEQL_VERSION=$CODEQL_VERSION" >> $GITHUB_OUTPUT
31+
publishlibs:
32+
environment: secure-publish
33+
needs: codeqlversion
34+
runs-on: ubuntu-latest
35+
strategy:
36+
matrix:
37+
language: ['powershell']
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
- name: Install CodeQL
42+
shell: bash
43+
run: |
44+
gh extension install github/gh-codeql
45+
gh codeql download "${{ needs.codeqlversion.outputs.codeql_version }}"
46+
gh codeql set-version "${{ needs.codeqlversion.outputs.codeql_version }}"
47+
env:
48+
GITHUB_TOKEN: ${{ github.token }}
49+
- name: Publish OS Microsoft CodeQL Lib Pack
50+
shell: bash
51+
run: |
52+
# Download latest qlpack
53+
gh codeql pack download "microsoft/$LANGUAGE-all"
54+
PACK_DIR="$HOME/.codeql/packages/microsoft/$LANGUAGE-all"
55+
VERSION_COUNT=$(ls -d "$PACK_DIR"/*/ | wc -l)
56+
[[ "$VERSION_COUNT" -ne 1 ]] && { echo "Expected exactly one version in $PACK_DIR, but found $VERSION_COUNT. Exiting."; exit 1; }
57+
58+
# Increment version
59+
CURRENT_VERSION=$(ls -v "$PACK_DIR" | tail -n 1)
60+
MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
61+
MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
62+
PATCH=$(echo "$CURRENT_VERSION" | cut -d. -f3)
63+
NEXT_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
64+
65+
# Extract dependencies from the existing qlpack.yml before deleting
66+
DEPENDENCIES=$(yq 'select(has("dependencies")) | .dependencies | {"dependencies": .}' "$LANGUAGE/ql/lib/qlpack.yml" 2>/dev/null)
67+
DATAEXTENSIONS=$(yq 'select(has("dataExtensions")) | .dataExtensions | {"dataExtensions": .}' "$LANGUAGE/ql/lib/qlpack.yml" 2>/dev/null)
68+
rm -f "$LANGUAGE/ql/lib/qlpack.yml" "$LANGUAGE/ql/lib/qlpack.lock"
69+
70+
# Create new qlpack.yml with modified content
71+
cat <<EOF > "$LANGUAGE/ql/lib/qlpack.yml"
72+
name: microsoft/$LANGUAGE-all
73+
version: $NEXT_VERSION
74+
extractor: $LANGUAGE
75+
groups:
76+
- $LANGUAGE
77+
- microsoft-all
78+
dbscheme: semmlecode.$LANGUAGE.dbscheme
79+
extractor: $LANGUAGE
80+
library: true
81+
upgrades: upgrades
82+
$DEPENDENCIES
83+
$DATAEXTENSIONS
84+
warnOnImplicitThis: true
85+
EOF
86+
87+
# Publish pack
88+
cat "$LANGUAGE/ql/lib/qlpack.yml"
89+
gh codeql pack publish "$LANGUAGE/ql/lib"
90+
env:
91+
LANGUAGE: ${{ matrix.language }}
92+
GITHUB_TOKEN: ${{ secrets.PACKAGE_PUBLISH }}
93+
publish:
94+
environment: secure-publish
95+
needs: codeqlversion
96+
runs-on: ubuntu-latest
97+
strategy:
98+
matrix:
99+
language: ['csharp', 'cpp', 'java', 'javascript', 'python', 'ruby', 'go', 'rust', 'swift', 'powershell']
100+
steps:
101+
- name: Checkout repository
102+
uses: actions/checkout@v4
103+
- name: Install CodeQL
104+
shell: bash
105+
run: |
106+
gh extension install github/gh-codeql
107+
gh codeql download "${{ needs.codeqlversion.outputs.codeql_version }}"
108+
gh codeql set-version "${{ needs.codeqlversion.outputs.codeql_version }}"
109+
env:
110+
GITHUB_TOKEN: ${{ github.token }}
111+
- name: Publish OS Microsoft CodeQL Pack
112+
shell: bash
113+
run: |
114+
# Download latest qlpack
115+
gh codeql pack download "microsoft/$LANGUAGE-queries"
116+
PACK_DIR="$HOME/.codeql/packages/microsoft/$LANGUAGE-queries"
117+
VERSION_COUNT=$(ls -d "$PACK_DIR"/*/ | wc -l)
118+
[[ "$VERSION_COUNT" -ne 1 ]] && { echo "Expected exactly one version in $PACK_DIR, but found $VERSION_COUNT. Exiting."; exit 1; }
119+
120+
# Increment version
121+
CURRENT_VERSION=$(ls -v "$PACK_DIR" | tail -n 1)
122+
MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
123+
MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
124+
PATCH=$(echo "$CURRENT_VERSION" | cut -d. -f3)
125+
NEXT_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
126+
127+
# Extract dependencies from the existing qlpack.yml before deleting
128+
DEPENDENCIES=$(yq 'select(has("dependencies")) | .dependencies | {"dependencies": .}' "$LANGUAGE/ql/src/qlpack.yml" 2>/dev/null)
129+
rm -f "$LANGUAGE/ql/src/qlpack.yml" "$LANGUAGE/ql/src/qlpack.lock"
130+
131+
# Create new qlpack.yml with modified content
132+
cat <<EOF > "$LANGUAGE/ql/src/qlpack.yml"
133+
name: microsoft/$LANGUAGE-queries
134+
version: $NEXT_VERSION
135+
extractor: $LANGUAGE
136+
groups:
137+
- $LANGUAGE
138+
- queries
139+
$DEPENDENCIES
140+
EOF
141+
142+
# Publish pack
143+
cat "$LANGUAGE/ql/src/qlpack.yml"
144+
gh codeql pack publish "$LANGUAGE/ql/src"
145+
env:
146+
LANGUAGE: ${{ matrix.language }}
147+
GITHUB_TOKEN: ${{ secrets.PACKAGE_PUBLISH }}
148+

0 commit comments

Comments
 (0)