Skip to content

Commit

Permalink
Add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
making committed Jul 31, 2024
1 parent 8e5de70 commit 0157313
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI
on:
push:
branches:
- main
paths:
- src/**
- pom.xml
- .github/workflows/*
pull_request:
branches:
- main
paths:
- src/**
- pom.xml
- .github/workflows/*
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_${GITHUB_SHA}
- 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_${GITHUB_SHA}
docker tag ghcr.io/${{ github.repository }}:jvm_${GITHUB_SHA} ghcr.io/${{ github.repository }}:jvm
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_${GITHUB_SHA})
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
save-image-jvm:
if: github.ref == 'refs/heads/main'
needs: build-jvm-image
uses: ./.github/workflows/save-images.yaml
with:
target: image.yaml
44 changes: 44 additions & 0 deletions .github/workflows/save-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Save Images
on:
workflow_call:
inputs:
target:
required: true
type: string
jobs:
save-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 fetch origin
git checkout images
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: image
path: .
- name: Commit and push changes
env:
TARGET: ${{ inputs.target }}
run: |
git add ${TARGET}
git commit -m ":robot: Update ${TARGET} for ${GITHUB_SHA}"
git push origin images

0 comments on commit 0157313

Please sign in to comment.