test tags push2 #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy Docker image | |
on: | |
push: | |
branches: | |
# WARNING: Change to production after testing! | |
- docker | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to GHCR | |
# WARNING: GHCR Personal Access Token expires! Recreate every 90 days. | |
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Set image tags | |
id: tag_version | |
run: | | |
if [ -n "${{ github.ref_type }}" ] && [ "${{ github.ref_type }}" == "tag" ]; then | |
VERSION=${{ github.ref_name }} # Use the Git tag as the version | |
else | |
VERSION=${{ github.sha }} # Default to commit SHA if no tag is found | |
fi | |
echo "${{ github.ref_type }} and ${{ github.ref_name }} and $VERSION" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Build and tag Docker image | |
run: | | |
IMAGE_NAME=ghcr.io/${{ github.repository }}:${{ env.VERSION }} | |
docker buildx build -t $IMAGE_NAME -t ghcr.io/${{ github.repository }}:latest --push . | |
echo "Image built and pushed with tags: $IMAGE_NAME and latest" |