name: Build / Release on: push: branches: [main] pull_request: branches: [main] workflow_dispatch: inputs: tag: description: "Version tag to create" required: false env: CARGO_TERM_COLOR: always jobs: build: strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - name: Install GNU tar if: runner.os == 'macOS' run: | brew install gnu-tar echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH - uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-rust-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Check formatting run: cargo fmt --all -- --check - name: Build run: cargo build --verbose - name: Run tests run: cargo test --verbose - name: Release build run: cargo build --release - name: Generate dbscheme if: ${{ matrix.os == 'ubuntu-latest' }} run: target/release/ruby-generator - uses: actions/upload-artifact@v2 if: ${{ matrix.os == 'ubuntu-latest' }} with: name: ruby.dbscheme path: ql/src/ruby.dbscheme - uses: actions/upload-artifact@v2 if: ${{ matrix.os == 'ubuntu-latest' }} with: name: TreeSitter.qll path: ql/src/codeql_ruby/ast/internal/TreeSitter.qll - uses: actions/upload-artifact@v2 with: name: extractor-${{ matrix.os }} path: | target/release/ruby-extractor target/release/ruby-extractor.exe retention-days: 1 compile-queries: runs-on: ubuntu-latest env: CODEQL_THREADS: 4 # TODO: remove this once it's set by the CLI steps: - uses: actions/checkout@v2 - name: Fetch CodeQL run: | LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1) gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST" unzip -q codeql-linux64.zip env: GITHUB_TOKEN: ${{ github.token }} - name: Build Query Pack run: | codeql/codeql pack create ql/src --output target/packs PACK_FOLDER=$(readlink -f target/packs/github/codeql-ruby/*) (cd ql/src; find queries \( -name '*.qhelp' -o -name '*.rb' -o -name '*.erb' \) -exec cp "{}" "${PACK_FOLDER}/{}" \;) - name: Compile with previous CodeQL versions run: | for version in $(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -3 | head -2); do rm -f codeql-linux64.zip gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$version" rm -rf codeql; unzip -q codeql-linux64.zip codeql/codeql query compile target/packs/* done env: GITHUB_TOKEN: ${{ github.token }} - uses: actions/upload-artifact@v2 with: name: codeql-ruby-queries path: | target/packs/* retention-days: 1 package: runs-on: ubuntu-latest needs: [build, compile-queries] steps: - uses: actions/checkout@v2 - uses: actions/download-artifact@v2 with: name: ruby.dbscheme path: ruby - uses: actions/download-artifact@v2 with: name: extractor-ubuntu-latest path: linux64 - uses: actions/download-artifact@v2 with: name: extractor-windows-latest path: win64 - uses: actions/download-artifact@v2 with: name: extractor-macos-latest path: osx64 - run: | mkdir -p ruby cp -r codeql-extractor.yml tools ql/src/ruby.dbscheme.stats ruby/ mkdir -p ruby/tools/{linux64,osx64,win64} cp linux64/ruby-extractor ruby/tools/linux64/extractor cp osx64/ruby-extractor ruby/tools/osx64/extractor cp win64/ruby-extractor.exe ruby/tools/win64/extractor.exe chmod +x ruby/tools/{linux64,osx64}/extractor zip -rq codeql-ruby.zip ruby - uses: actions/upload-artifact@v2 with: name: codeql-ruby-pack path: codeql-ruby.zip retention-days: 1 - uses: actions/download-artifact@v2 with: name: codeql-ruby-queries path: qlpacks - run: | echo '{ "provide": [ "ruby/codeql-extractor.yml", "qlpacks/*/*/*/qlpack.yml" ] }' > .codeqlmanifest.json zip -rq codeql-ruby-bundle.zip .codeqlmanifest.json ruby qlpacks - uses: actions/upload-artifact@v2 with: name: codeql-ruby-bundle path: codeql-ruby-bundle.zip retention-days: 1 - if: ${{ github.event.inputs.tag }} run: | gh release create --prerelease \ --title "CodeQL Ruby (${{ github.event.inputs.tag }})" \ --target "${{ github.sha }}" \ "${{ github.event.inputs.tag }}" \ codeql-ruby-bundle.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}