Skip to content

Add Queries for Java Android #13

Add Queries for Java Android

Add Queries for Java Android #13

Workflow file for this run

name: "Java - Run Tests and Publish CodeQL Pack"
on:
workflow_dispatch:
pull_request:
branches: [ "dev" ]
paths:
- 'codeql-custom-queries-java/**'
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install CodeQL CLI
id: install-codeql
uses: github/codeql-action/setup-codeql@v4
- name: Run Tests
working-directory: codeql-custom-queries-java
run: |
export PATH="$(dirname ${{ steps.install-codeql.outputs.codeql-path }}):$PATH"
echo "Installation des dépendances du pack..."
codeql pack install
echo "Exécution des tests unitaires CodeQL..."
codeql test run . --format=text
publish:
name: Publish Pack
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
permissions:
packages: write
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install CodeQL CLI
id: install-codeql
uses: github/codeql-action/setup-codeql@v4
- name: Increment version and publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export PATH="$(dirname ${{ steps.install-codeql.outputs.codeql-path }}):$PATH"
cd codeql-custom-queries-java
git pull --rebase origin main
# 1. Détection du fichier de pack
PACK_FILE=$(ls qlpack.yml 2>/dev/null || ls codeql-pack.yml 2>/dev/null)
if [ -z "$PACK_FILE" ]; then echo "Pack file not found"; exit 1; fi
# 2. Récupération de la version actuelle sur le GitHub Container Registry
OWNER="green-code-initiative"
PACKAGE_NAME="java-queries"
RESPONSE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/users/$OWNER/packages/container/$PACKAGE_NAME/versions")
LATEST_VERSION=$(echo "$RESPONSE" | jq -r '.[0].metadata.container.tags[0]' 2>/dev/null)
if [ "$LATEST_VERSION" == "null" ] || [ -z "$LATEST_VERSION" ]; then
NEW_VERSION="1.0.0"
else
echo "Dernière version trouvée : $LATEST_VERSION"
MAJOR=$(echo $LATEST_VERSION | cut -d. -f1)
MINOR=$(echo $LATEST_VERSION | cut -d. -f2)
PATCH=$(echo $LATEST_VERSION | cut -d. -f3)
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
fi
echo "Nouvelle version déterminée : $NEW_VERSION"
sed -i "s/^version: .*/version: $NEW_VERSION/" "$PACK_FILE"
echo "Publication du pack sur GitHub Packages..."
codeql pack publish
- name: Commit version update
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add codeql-custom-queries-actions/
git diff --staged --quiet || git commit -m "chore: bump java pack version to match registry [skip ci]"
git push origin main