Fix GitHub workflow: publish to Maven Central + create GitHub release on pull-request #36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release | |
on: | |
workflow_dispatch: | |
pull_request: | |
push: | |
branches: | |
- master | |
jobs: | |
build_faiss: | |
runs-on: ubuntu-latest | |
name: Build faiss native | |
steps: | |
- uses: actions/checkout@master | |
with: | |
submodules: true | |
- uses: whoan/docker-build-with-cache-action@v5 | |
with: | |
username: ${{ github.actor }} | |
password: "${{ secrets.GITHUB_TOKEN }}" | |
registry: docker.pkg.github.com | |
image_name: jfaiss-cpu | |
dockerfile: Dockerfile | |
- run: docker run -v "/home/runner/work/jfaiss-cpu/jfaiss-cpu":"/github/workspace" docker.pkg.github.com/criteo/jfaiss-cpu/jfaiss-cpu | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: faiss_JNI_and_SO | |
path: build | |
build_jfaiss: | |
needs: build_faiss | |
runs-on: ubuntu-latest | |
name: Build jfaiss-cpu | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Read GPG private key | |
run: echo -ne "$GPG_PRIVATE_KEY" | base64 --decode > $RUNNER_TEMP/key.asc | |
env: | |
GPG_PRIVATE_KEY: ${{ secrets.MAVEN_SECRING_GPG_BASE64 }} | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: faiss_JNI_and_SO | |
path: build_copy | |
- name: Move build artifacts | |
run: | | |
rm -rf src/main/java/com/vectorsearch/faiss/swig | |
cp -r build_copy/java/com/vectorsearch/faiss/swig src/main/java/com/vectorsearch/faiss/swig | |
rm -rf src/main/resources | |
cp -r build_copy/resources src/main/resources | |
- name: Extract FAISS version | |
id: faiss_version | |
run: | | |
FAISS_VERSION="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" | |
echo "::set-output name=version::$FAISS_VERSION" | |
- name: Set version | |
id: version | |
run: | | |
VERSION="${FAISS_VERSION}-$(git rev-parse --short HEAD)" | |
mvn -B versions:set -DnewVersion=$VERSION | |
echo "::set-output name=version::$VERSION" | |
env: | |
FAISS_VERSION: ${{ steps.faiss_version.outputs.version }} | |
- name: Set up Maven Central Repository | |
uses: warrenseine/setup-java@v1 | |
env: | |
ACTIONS_ALLOW_UNSECURE_COMMANDS: true | |
with: | |
java-version: "1.8.0" | |
java-package: jdk | |
architecture: x64 | |
server-id: ossrh | |
server-username: MAVEN_USERNAME | |
server-password: MAVEN_PASSWORD | |
gpg-private-key-path: ${{ runner.temp }}/key.asc | |
gpg-passphrase: MAVEN_GPG_PASSPHRASE | |
- name: Clean GPG private key | |
if: ${{ always() }} | |
run: rm -f $RUNNER_TEMP/key.asc | |
- name: Publish to the Maven Central Repository | |
run: mvn -B -DskipTests -P deploy deploy | |
env: | |
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }} | |
MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} | |
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_SECRING_PASSWORD }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: jfaiss-cpu | |
path: ./target/jfaiss-cpu-${{ steps.version.outputs.version }}.jar | |
- name: Create release | |
id: release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.faiss_version.outputs.version }} | |
release_name: Release ${{ steps.version.outputs.version }} | |
draft: false | |
prerelease: false | |
- name: Upload release asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
ACTIONS_ALLOW_UNSECURE_COMMANDS: true | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.release.outputs.upload_url }} | |
asset_path: ./target/jfaiss-cpu-${{ steps.version.outputs.version }}.jar | |
asset_name: jfaiss-cpu-${{ steps.version.outputs.version }}.jar | |
asset_content_type: application/java-archive |