Refactor Docker workflow to use REPO_NAME environment variable

This commit is contained in:
coconut49 2023-10-24 13:30:11 +08:00
parent 0e34820ffe
commit 587b808631
No known key found for this signature in database

View file

@ -7,7 +7,11 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
REPO_NAME: ${{ github.repository }}
steps: steps:
- name: Convert repo name to lowercase
run: echo "REPO_NAME=$(echo "$REPO_NAME" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up QEMU - name: Set up QEMU
@ -20,24 +24,19 @@ jobs:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: set lower case repository name
run: |
echo "REPOSITORY_LC=${REPOSITORY,,}" >>${GITHUB_ENV}
env:
REPOSITORY: '${{ github.repository }}'
- name: Extract metadata (tags, labels) for Docker - name: Extract metadata (tags, labels) for Docker
id: meta id: meta
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: ghcr.io/${ REPOSITORY_LC } images: ghcr.io/${{ env.REPO_NAME }}
- name: Get tag to build - name: Get tag to build
id: tag id: tag
run: | run: |
echo "latest=ghcr.io/${ REPOSITORY_LC }:latest" >> $GITHUB_OUTPUT echo "latest=ghcr.io/${{ env.REPO_NAME }}:latest" >> $GITHUB_OUTPUT
if [[ -z "${{ github.event.inputs.tag }}" ]]; then if [[ -z "${{ github.event.inputs.tag }}" ]]; then
echo "versioned=ghcr.io/${ REPOSITORY_LC }:${{ github.ref_name }}" >> $GITHUB_OUTPUT echo "versioned=ghcr.io/${{ env.REPO_NAME }}:${{ github.ref_name }}" >> $GITHUB_OUTPUT
else else
echo "versioned=ghcr.io/${ REPOSITORY_LC }:${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT echo "versioned=ghcr.io/${{ env.REPO_NAME }}:${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
fi fi
- name: Build and release Docker images - name: Build and release Docker images
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5