Skip to content

Fix

Fix #909

Workflow file for this run

name: CI
on:
push:
branches:
- main
paths:
- src/**
- pom.xml
- .github/workflows/ci.yml
pull_request:
branches:
- main
paths:
- src/**
- pom.xml
- .github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
cache: 'maven'
- name: mvn test
env:
_JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
run: ./mvnw -V --no-transfer-progress test
- name: Upload build artifacts
uses: actions/upload-artifact@v2
with:
name: build-artifacts
path: target
build-jvm-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: test
steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
cache: 'maven'
- name: Download build artifacts
uses: actions/download-artifact@v2
with:
name: build-artifacts
path: target
- name: build image
run: ./mvnw -V --no-transfer-progress spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=ghcr.io/${{ github.repository }}:jvm
- name: Login to GitHub Container Registry
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: docker push
if: github.ref == 'refs/heads/main'
run: docker push ghcr.io/${{ github.repository }}:jvm
- name: Generate digest
if: github.ref == 'refs/heads/main'
run: |
cat <<EOF > image.yaml
image: $(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}:jvm)
git_revision: ${GITHUB_SHA}
EOF
- name: Upload artifact
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v2
with:
name: image
path: image.yaml
build-native-image:
if: github.ref == 'refs/heads/skip'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: test
steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
cache: 'maven'
- name: Download build artifacts
uses: actions/download-artifact@v2
with:
name: build-artifacts
path: target
- name: build image
run: ./mvnw -V --no-transfer-progress -Pnative clean spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=ghcr.io/${{ github.repository }}:native
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: docker push
run: |
docker push ghcr.io/${{ github.repository }}:native
docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}:native
- name: Generate digest
if: github.ref == 'refs/heads/main'
run: |
cat <<EOF > image_native.yaml
image: $(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}:native)
git_revision: ${GITHUB_SHA}
EOF
- name: Upload artifact
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v2
with:
name: image
path: image_native.yaml
save-image:
if: github.ref == 'refs/heads/main'
needs: [ build-jvm-image ]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: git config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git remote set-url origin https://github-actions:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
- name: Ensure images branch exists
run: |
if ! git ls-remote --exit-code --heads origin images; then
git checkout --orphan images
git reset --hard
git commit --allow-empty -m ":robot: Initial commit on images branch"
git push origin images
fi
- name: Checkout images branch
run: git checkout images
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: image
path: .
- name: Commit and push changes
run: |
git add -A
git commit -m ":robot: Add Docker image digest for ${GITHUB_SHA}"
git push origin images
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}