Skip to content

Commit a3c5e48

Browse files
authored
Update microsoft-codeql-pack-publish.yml
1 parent 082141e commit a3c5e48

File tree

1 file changed

+59
-53
lines changed

1 file changed

+59
-53
lines changed

.github/workflows/microsoft-codeql-pack-publish.yml

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
name: Microsoft CodeQL Pack Publish
22

33
on:
4-
push:
5-
branches:
6-
- dilan/publish-opensource-packs
4+
workflow_dispatch:
75

86
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
912
codeqlversion:
13+
needs: check-branch
1014
runs-on: ubuntu-latest
1115
outputs:
1216
codeql_version: ${{ steps.set_codeql_version.outputs.codeql_version }}
@@ -25,6 +29,7 @@ jobs:
2529
CODEQL_VERSION="${CURRENT_TAG#codeql-cli/}"
2630
echo "CODEQL_VERSION=$CODEQL_VERSION" >> $GITHUB_OUTPUT
2731
publishlibs:
32+
environment: secure-publish
2833
needs: codeqlversion
2934
runs-on: ubuntu-latest
3035
strategy:
@@ -85,58 +90,59 @@ jobs:
8590
env:
8691
LANGUAGE: ${{ matrix.language }}
8792
GITHUB_TOKEN: ${{ secrets.PACKAGE_PUBLISH }}
88-
# publish:
89-
# needs: codeqlversion
90-
# runs-on: ubuntu-latest
91-
# strategy:
92-
# matrix:
93-
# language: ['csharp', 'cpp', 'java', 'javascript', 'python', 'ruby', 'go', 'rust', 'swift', 'powershell']
94-
# steps:
95-
# - name: Checkout repository
96-
# uses: actions/checkout@v4
97-
# - name: Install CodeQL
98-
# shell: bash
99-
# run: |
100-
# gh extension install github/gh-codeql
101-
# gh codeql download "${{ needs.codeqlversion.outputs.codeql_version }}"
102-
# gh codeql set-version "${{ needs.codeqlversion.outputs.codeql_version }}"
103-
# env:
104-
# GITHUB_TOKEN: ${{ github.token }}
105-
# - name: Publish OS Microsoft CodeQL Pack
106-
# shell: bash
107-
# run: |
108-
# # Download latest qlpack
109-
# gh codeql pack download "microsoft/$LANGUAGE-queries"
110-
# PACK_DIR="$HOME/.codeql/packages/microsoft/$LANGUAGE-queries"
111-
# VERSION_COUNT=$(ls -d "$PACK_DIR"/*/ | wc -l)
112-
# [[ "$VERSION_COUNT" -ne 1 ]] && { echo "Expected exactly one version in $PACK_DIR, but found $VERSION_COUNT. Exiting."; exit 1; }
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; }
113119
114-
# # Increment version
115-
# CURRENT_VERSION=$(ls -v "$PACK_DIR" | tail -n 1)
116-
# MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
117-
# MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
118-
# PATCH=$(echo "$CURRENT_VERSION" | cut -d. -f3)
119-
# NEXT_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
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))"
120126
121-
# # Extract dependencies from the existing qlpack.yml before deleting
122-
# DEPENDENCIES=$(yq 'select(has("dependencies")) | .dependencies | {"dependencies": .}' "$LANGUAGE/ql/src/qlpack.yml" 2>/dev/null)
123-
# rm -f "$LANGUAGE/ql/src/qlpack.yml" "$LANGUAGE/ql/src/qlpack.lock"
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"
124130
125-
# # Create new qlpack.yml with modified content
126-
# cat <<EOF > "$LANGUAGE/ql/src/qlpack.yml"
127-
# name: microsoft/$LANGUAGE-queries
128-
# version: $NEXT_VERSION
129-
# extractor: $LANGUAGE
130-
# groups:
131-
# - $LANGUAGE
132-
# - queries
133-
# $DEPENDENCIES
134-
# EOF
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
135141
136-
# # Publish pack
137-
# cat "$LANGUAGE/ql/src/qlpack.yml"
138-
# gh codeql pack publish "$LANGUAGE/ql/src"
139-
# env:
140-
# LANGUAGE: ${{ matrix.language }}
141-
# GITHUB_TOKEN: ${{ secrets.PACKAGE_PUBLISH }}
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 }}
142148

0 commit comments

Comments
 (0)