diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml deleted file mode 100644 index 8a0ea66..0000000 --- a/.github/workflows/build-image.yml +++ /dev/null @@ -1,56 +0,0 @@ ---- -name: Build Image -on: - workflow_call: - inputs: - push: - type: boolean - default: false - -permissions: - contents: read -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - run: mvn --batch-mode --update-snapshots verify - - uses: docker/setup-qemu-action@v3 - - uses: docker/setup-buildx-action@v3 - - uses: docker/metadata-action@v5 - id: meta - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - # output 0.1.2 - type=semver,pattern={{version}} - # output 0.1 - type=semver,pattern={{major}}.{{minor}} - # disabled if major zero - type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} - # set latest tag for default branch - type=raw,value=latest,enable={{is_default_branch}} - type=ref,event=branch - type=ref,event=pr - - uses: docker/login-action@v3 - if: ${{ inputs.push }} - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - uses: docker/build-push-action@v5 - with: - context: . - push: ${{ inputs.push }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ecd3610..41e8517 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,4 +7,19 @@ permissions: contents: read jobs: build-image: - uses: ./.github/workflows/build-image.yml + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - run: mvn --batch-mode --update-snapshots verify + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/build-push-action@v5 + with: + context: . + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 57aedb5..6dfeebd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,12 +9,51 @@ on: permissions: contents: read +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: build-push-image: if: ${{ github.repository == 'statnett/k3a-lag-exporter' }} permissions: contents: read packages: write - uses: ./.github/workflows/build-image.yml - with: - push: true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - run: mvn --batch-mode --update-snapshots verify + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + # output 0.1.2 + type=semver,pattern={{version}} + # output 0.1 + type=semver,pattern={{major}}.{{minor}} + # disabled if major zero + type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} + # set latest tag for default branch + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=branch + type=ref,event=pr + - uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max