mirror of
https://github.com/linuxserver/github-workflows.git
synced 2026-03-02 00:02:48 +08:00
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com>
238 lines
14 KiB
YAML
238 lines
14 KiB
YAML
name: Docker Mod Builder
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
BASEIMAGE:
|
|
required: true
|
|
type: string
|
|
MODNAME:
|
|
required: true
|
|
type: string
|
|
ENDPOINT:
|
|
required: true
|
|
type: string
|
|
GITHUB_REPO:
|
|
required: true
|
|
type: string
|
|
MOD_VERSION:
|
|
required: false
|
|
type: string
|
|
MOD_VERSION_OVERRIDE:
|
|
required: false
|
|
type: string
|
|
MULTI_ARCH:
|
|
required: false
|
|
type: string
|
|
secrets:
|
|
CR_USER:
|
|
required: false
|
|
CR_PAT:
|
|
required: false
|
|
DOCKERUSER:
|
|
required: false
|
|
DOCKERPASS:
|
|
required: false
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check Out Repo (Commit)
|
|
uses: actions/checkout@v6
|
|
if: ${{ github.event_name != 'pull_request_target' }}
|
|
|
|
- name: Check Out Repo (PR)
|
|
uses: actions/checkout@v6
|
|
if: ${{ github.event_name == 'pull_request_target' }}
|
|
with:
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
- name: Set Vars
|
|
run: |
|
|
echo "GITHUB_REPO=${{ inputs.GITHUB_REPO }}" >> $GITHUB_ENV
|
|
echo "ENDPOINT=${{ inputs.ENDPOINT }}" >> $GITHUB_ENV
|
|
echo "BASEIMAGE=${{ inputs.BASEIMAGE }}" >> $GITHUB_ENV
|
|
echo "MODNAME=${{ inputs.MODNAME }}" >> $GITHUB_ENV
|
|
echo "MOD_VERSION=${{ inputs.MOD_VERSION }}" >> $GITHUB_ENV
|
|
echo "MOD_VERSION_OVERRIDE=${{ inputs.MOD_VERSION_OVERRIDE || 'false' }}" >> $GITHUB_ENV
|
|
echo "MULTI_ARCH=${{ inputs.MULTI_ARCH || 'false' }}" >> $GITHUB_ENV
|
|
echo "> [!NOTE]" >> $GITHUB_STEP_SUMMARY
|
|
echo "> GITHUB_REPO=${{ inputs.GITHUB_REPO }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "> ENDPOINT=${{ inputs.ENDPOINT }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "> BASEIMAGE=${{ inputs.BASEIMAGE }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "> MODNAME=${{ inputs.MODNAME }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "> MOD_VERSION=${{ inputs.MOD_VERSION }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "> MOD_VERSION_OVERRIDE=${{ inputs.MOD_VERSION_OVERRIDE || 'false' }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "> MULTI_ARCH=${{ inputs.MULTI_ARCH || 'false' }}" >> $GITHUB_STEP_SUMMARY
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Build image
|
|
run: |
|
|
docker buildx build --no-cache --build-arg MOD_VERSION=${MOD_VERSION} -t ${{ github.sha }} --platform linux/amd64 .
|
|
if [[ "${MULTI_ARCH,,}" == "true" ]]; then
|
|
docker buildx build --no-cache --build-arg MOD_VERSION=${MOD_VERSION} -t arm64v8-${{ github.sha }} --platform linux/arm64/v8 .
|
|
fi
|
|
|
|
- name: Tag image (Commit)
|
|
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository }}
|
|
run: |
|
|
DOCKERHUB_TAGS="${ENDPOINT}:${BASEIMAGE}-${MODNAME} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}"
|
|
if [[ -n "${MOD_VERSION}" ]]; then
|
|
if [[ "${MOD_VERSION_OVERRIDE,,}" == "true" ]]; then
|
|
DOCKERHUB_TAGS="${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}"
|
|
else
|
|
DOCKERHUB_TAGS="${DOCKERHUB_TAGS} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}"
|
|
fi
|
|
fi
|
|
echo "DOCKERHUB_TAGS=${DOCKERHUB_TAGS}" >> $GITHUB_ENV
|
|
if [[ "${MULTI_ARCH,,}" == "true" ]]; then
|
|
for i in ${DOCKERHUB_TAGS}; do
|
|
docker tag ${{ github.sha }} ${i/:/:amd64-}
|
|
docker tag arm64v8-${{ github.sha }} ${i/:/:arm64v8-}
|
|
ighcr="${i/#/ghcr.io\/}"
|
|
docker tag ${{ github.sha }} ${ighcr/:/:amd64-}
|
|
docker tag arm64v8-${{ github.sha }} ${ighcr/:/:arm64v8-}
|
|
done
|
|
else
|
|
for i in ${DOCKERHUB_TAGS}; do
|
|
docker tag ${{ github.sha }} ${i}
|
|
docker tag ${{ github.sha }} ${i/#/ghcr.io\/}
|
|
done
|
|
fi
|
|
|
|
- name: Tag image (PR)
|
|
if: ${{ env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name) }}
|
|
run: |
|
|
if [[ "${MULTI_ARCH,,}" == "true" ]]; then
|
|
docker tag ${{ github.sha }} ${ENDPOINT}:amd64-pull_request_${{ github.event.pull_request.number }}
|
|
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:amd64-pull_request_${{ github.event.pull_request.number }}
|
|
docker tag arm64v8-${{ github.sha }} ${ENDPOINT}:arm64v8-pull_request_${{ github.event.pull_request.number }}
|
|
docker tag arm64v8-${{ github.sha }} ghcr.io/${ENDPOINT}:arm64v8-pull_request_${{ github.event.pull_request.number }}
|
|
else
|
|
docker tag ${{ github.sha }} ${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}
|
|
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}
|
|
fi
|
|
|
|
- name: Credential check
|
|
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository || env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name) }}
|
|
run: |
|
|
echo "CR_USER=${{ secrets.CR_USER }}" >> $GITHUB_ENV
|
|
echo "CR_PAT=${{ secrets.CR_PAT }}" >> $GITHUB_ENV
|
|
echo "DOCKERUSER=${{ secrets.DOCKERUSER }}" >> $GITHUB_ENV
|
|
echo "DOCKERPASS=${{ secrets.DOCKERPASS }}" >> $GITHUB_ENV
|
|
if [[ "${{ secrets.CR_USER }}" == "" && "${{ secrets.CR_PAT }}" == "" && "${{ secrets.DOCKERUSER }}" == "" && "${{ secrets.DOCKERPASS }}" == "" ]]; then
|
|
echo "::error::Push credential secrets missing."
|
|
echo "::error::You must set either CR_USER & CR_PAT or DOCKERUSER & DOCKERPASS as secrets in your repo settings."
|
|
echo "::error::See https://github.com/linuxserver/docker-mods/blob/master/README.md for more information/instructions."
|
|
exit 1
|
|
fi
|
|
|
|
- name: Login to GitHub Container Registry
|
|
if: ${{ ((github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository || env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name)) && env.CR_USER && env.CR_PAT }}
|
|
run: |
|
|
echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.CR_USER }} --password-stdin
|
|
|
|
- name: Push tags to GitHub Container Registry (Commit)
|
|
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository && env.CR_USER && env.CR_PAT }}
|
|
run: |
|
|
if [[ "${MULTI_ARCH,,}" == "true" ]]; then
|
|
printf "\n## Pushed the following images/tags to GHCR:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
for i in ${DOCKERHUB_TAGS}; do
|
|
ighcr="${i/#/ghcr.io\/}"
|
|
docker push ${ighcr/:/:amd64-}
|
|
echo "\`${ighcr/:/:amd64-}\`" >> $GITHUB_STEP_SUMMARY
|
|
docker push ${ighcr/:/:arm64v8-}
|
|
echo "\`${ighcr/:/:arm64v8-}\`" >> $GITHUB_STEP_SUMMARY
|
|
done
|
|
printf "\n## Pushed the following manifests to GHCR:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
for i in ${DOCKERHUB_TAGS}; do
|
|
ighcr="${i/#/ghcr.io\/}"
|
|
docker buildx imagetools create -t ${ighcr} ${ighcr/:/:amd64-} ${ighcr/:/:arm64v8-}
|
|
echo "\`${ighcr}\`" >> $GITHUB_STEP_SUMMARY
|
|
done
|
|
else
|
|
printf "\n## Pushed the following images/tags to GHCR:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
for i in ${DOCKERHUB_TAGS}; do
|
|
ighcr="${i/#/ghcr.io\/}"
|
|
docker push ${ighcr}
|
|
echo "\`${ighcr}\`" >> $GITHUB_STEP_SUMMARY
|
|
done
|
|
fi
|
|
|
|
- name: Push tags to GitHub Container Registry (PR)
|
|
if: ${{ env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name) && env.CR_USER && env.CR_PAT }}
|
|
run: |
|
|
if [[ "${MULTI_ARCH,,}" == "true" ]]; then
|
|
docker push ghcr.io/${ENDPOINT}:amd64-pull_request_${{ github.event.pull_request.number }}
|
|
docker push ghcr.io/${ENDPOINT}:arm64v8-pull_request_${{ github.event.pull_request.number }}
|
|
printf "\n## Pushed the following PR images/tags to GHCR:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`ghcr.io/${ENDPOINT}:amd64-pull_request_${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`ghcr.io/${ENDPOINT}:arm64v8-pull_request_${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
|
|
docker buildx imagetools create -t ghcr.io/${ENDPOINT}:pull_request_${{ github.event.pull_request.number }} ghcr.io/${ENDPOINT}:amd64-pull_request_${{ github.event.pull_request.number }} ghcr.io/${ENDPOINT}:arm64v8-pull_request_${{ github.event.pull_request.number }}
|
|
printf "\n## Pushed the following PR manifest to GHCR:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`ghcr.io/${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
docker push ghcr.io/${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}
|
|
printf "\n## Pushed the following PR image/tag to GHCR:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`ghcr.io/${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
- name: Add GHCR push comment to PR
|
|
uses: peter-evans/create-or-update-comment@v5.0.0
|
|
if: ${{ env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name) && env.CR_USER && env.CR_PAT }}
|
|
with:
|
|
token: ${{ secrets.CR_PAT }}
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
body: |
|
|
PR build pushed to `ghcr.io/${{ inputs.ENDPOINT }}:pull_request_${{ github.event.pull_request.number }}`
|
|
|
|
- name: Login to DockerHub
|
|
if: ${{ ((github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository || env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name)) && env.DOCKERUSER && env.DOCKERPASS }}
|
|
run: |
|
|
echo ${{ secrets.DOCKERPASS }} | docker login -u ${{ secrets.DOCKERUSER }} --password-stdin
|
|
|
|
- name: Push tags to DockerHub (Commit)
|
|
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository && env.DOCKERUSER && env.DOCKERPASS }}
|
|
run: |
|
|
if [[ "${MULTI_ARCH,,}" == "true" ]]; then
|
|
printf "\n## Pushed the following images/tags to Docker Hub:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
for i in ${DOCKERHUB_TAGS}; do
|
|
docker push ${i/:/:amd64-}
|
|
echo "\`${i/:/:amd64-}\`" >> $GITHUB_STEP_SUMMARY
|
|
docker push ${i/:/:arm64v8-}
|
|
echo "\`${i/:/:arm64v8-}\`" >> $GITHUB_STEP_SUMMARY
|
|
done
|
|
printf "\n## Pushed the following manifests to Docker Hub:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
for i in ${DOCKERHUB_TAGS}; do
|
|
docker buildx imagetools create -t ${i} ${i/:/:amd64-} ${i/:/:arm64v8-}
|
|
echo "\`${i}\`" >> $GITHUB_STEP_SUMMARY
|
|
done
|
|
else
|
|
printf "\n## Pushed the following images/tags to Docker Hub:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
for i in ${DOCKERHUB_TAGS}; do
|
|
docker push ${i}
|
|
echo "\`${i}\`" >> $GITHUB_STEP_SUMMARY
|
|
done
|
|
fi
|
|
|
|
- name: Push tags to DockerHub (PR)
|
|
if: ${{ env.GITHUB_REPO == format('{0}/{1}', github.event.pull_request.base.repo.owner.login, github.event.pull_request.base.repo.name) && env.DOCKERUSER && env.DOCKERPASS }}
|
|
run: |
|
|
if [[ "${MULTI_ARCH,,}" == "true" ]]; then
|
|
docker push ${ENDPOINT}:amd64-pull_request_${{ github.event.pull_request.number }}
|
|
docker push ${ENDPOINT}:arm64v8-pull_request_${{ github.event.pull_request.number }}
|
|
printf "\n## Pushed the following PR images/tags to Docker Hub:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`${ENDPOINT}:amd64-pull_request_${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`${ENDPOINT}:arm64v8-pull_request_${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
|
|
docker buildx imagetools create -t ${ENDPOINT}:pull_request_${{ github.event.pull_request.number }} ${ENDPOINT}:amd64-pull_request_${{ github.event.pull_request.number }} ${ENDPOINT}:arm64v8-pull_request_${{ github.event.pull_request.number }}
|
|
printf "\n## Pushed the following PR manifest to Docker Hub:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
docker push ${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}
|
|
printf "\n## Pushed the following PR image/tag to Docker Hub:\n\n" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
|
|
fi
|