|
1 | 1 | name: Microsoft CodeQL Pack Publish
|
2 | 2 |
|
3 | 3 | on:
|
4 |
| - push: |
5 |
| - branches: |
6 |
| - - dilan/publish-opensource-packs |
| 4 | + workflow_dispatch: |
7 | 5 |
|
8 | 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 |
9 | 12 | codeqlversion:
|
| 13 | + needs: check-branch |
10 | 14 | runs-on: ubuntu-latest
|
11 | 15 | outputs:
|
12 | 16 | codeql_version: ${{ steps.set_codeql_version.outputs.codeql_version }}
|
|
25 | 29 | CODEQL_VERSION="${CURRENT_TAG#codeql-cli/}"
|
26 | 30 | echo "CODEQL_VERSION=$CODEQL_VERSION" >> $GITHUB_OUTPUT
|
27 | 31 | publishlibs:
|
| 32 | + environment: secure-publish |
28 | 33 | needs: codeqlversion
|
29 | 34 | runs-on: ubuntu-latest
|
30 | 35 | strategy:
|
@@ -85,58 +90,59 @@ jobs:
|
85 | 90 | env:
|
86 | 91 | LANGUAGE: ${{ matrix.language }}
|
87 | 92 | 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; } |
113 | 119 |
|
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))" |
120 | 126 |
|
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" |
124 | 130 |
|
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 |
135 | 141 |
|
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 }} |
142 | 148 |
|
0 commit comments