mirror of
https://github.com/linuxserver/github-workflows.git
synced 2026-03-02 00:02:48 +08:00
Bumps [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) from 3.0.0 to 3.0.1. - [Release notes](https://github.com/peter-evans/create-or-update-comment/releases) - [Commits](https://github.com/peter-evans/create-or-update-comment/compare/v3.0.0...v3.0.1) --- updated-dependencies: - dependency-name: peter-evans/create-or-update-comment dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
161 lines
9.0 KiB
YAML
161 lines
9.0 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
|
|
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@v3
|
|
if: ${{ github.event_name != 'pull_request_target' }}
|
|
|
|
- name: Check Out Repo (PR)
|
|
uses: actions/checkout@v3
|
|
if: ${{ github.event_name == 'pull_request_target' }}
|
|
with:
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
- name: Set Vars
|
|
run: |
|
|
echo "BASEIMAGE=${{ inputs.BASEIMAGE }}" >> $GITHUB_ENV
|
|
echo "BASEIMAGE=${{ inputs.BASEIMAGE }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "MODNAME=${{ inputs.MODNAME }}" >> $GITHUB_ENV
|
|
echo "MODNAME=${{ inputs.MODNAME }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "ENDPOINT=${{ inputs.ENDPOINT }}" >> $GITHUB_ENV
|
|
echo "ENDPOINT=${{ inputs.ENDPOINT }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "GITHUB_REPO=${{ inputs.GITHUB_REPO }}" >> $GITHUB_ENV
|
|
echo "GITHUB_REPO=${{ inputs.GITHUB_REPO }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "MOD_VERSION=${{ inputs.MOD_VERSION }}" >> $GITHUB_ENV
|
|
echo "MOD_VERSION=${{ inputs.MOD_VERSION }}" >> $GITHUB_STEP_SUMMARY
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
- name: Build image
|
|
run: |
|
|
docker buildx build --no-cache --build-arg MOD_VERSION=${MOD_VERSION} -t ${{ github.sha }} .
|
|
|
|
- name: Tag image (Commit)
|
|
if: ${{ github.event_name == 'push' && github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository }}
|
|
run: |
|
|
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
|
|
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
|
|
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
|
|
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
|
|
if [[ -n "${MOD_VERSION}" ]]; then
|
|
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}
|
|
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}
|
|
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}
|
|
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}
|
|
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: |
|
|
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 }}
|
|
|
|
- name: Credential check
|
|
if: ${{ github.event_name == 'push' && 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.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.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository && env.CR_USER && env.CR_PAT }}
|
|
run: |
|
|
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
|
|
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
|
|
echo "Pushed the following images/tags to GHCR:" >> $GITHUB_STEP_SUMMARY
|
|
echo "ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}" >> $GITHUB_STEP_SUMMARY
|
|
echo "ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
|
|
if [[ -n "${MOD_VERSION}" ]]; then
|
|
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}
|
|
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}
|
|
echo "ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}" >> $GITHUB_STEP_SUMMARY
|
|
echo "ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
|
|
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: |
|
|
docker push ghcr.io/${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}
|
|
echo "Pushed the following PR image/tag to GHCR:" >> $GITHUB_STEP_SUMMARY
|
|
echo "ghcr.io/${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY
|
|
|
|
- name: Add GHCR push comment to PR
|
|
uses: peter-evans/create-or-update-comment@v3.0.1
|
|
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.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.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.GITHUB_REPO == github.repository && env.DOCKERUSER && env.DOCKERPASS }}
|
|
run: |
|
|
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
|
|
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
|
|
echo "Pushed the following images/tags to Docker Hub:" >> $GITHUB_STEP_SUMMARY
|
|
echo "${ENDPOINT}:${BASEIMAGE}-${MODNAME}" >> $GITHUB_STEP_SUMMARY
|
|
echo "${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
|
|
if [[ -n "${MOD_VERSION}" ]]; then
|
|
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}
|
|
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}
|
|
echo "${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}" >> $GITHUB_STEP_SUMMARY
|
|
echo "${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${MOD_VERSION}-${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
|
|
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: |
|
|
docker push ${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}
|
|
echo "Pushed the following PR image/tag to Docker Hub:" >> $GITHUB_STEP_SUMMARY
|
|
echo "${ENDPOINT}:pull_request_${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY
|