added git tagging
This commit is contained in:
61
.github/workflows/build.yml
vendored
61
.github/workflows/build.yml
vendored
@@ -94,6 +94,26 @@ jobs:
|
||||
# working-directory: ${{ needs.detect-project.outputs.project-dir }}
|
||||
# run: cargo clippy -- -D warnings
|
||||
|
||||
set-tag:
|
||||
name: Set Tag Name
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
tag_name: ${{ steps.set_tag.outputs.tag_name }}
|
||||
steps:
|
||||
- name: Determine tag name
|
||||
id: set_tag
|
||||
run: |
|
||||
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
|
||||
TAG_NAME="${GITHUB_REF_NAME}"
|
||||
elif [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
|
||||
TAG_NAME="latest"
|
||||
elif [[ "${GITHUB_REF}" == "refs/heads/development" ]]; then
|
||||
TAG_NAME="development"
|
||||
else
|
||||
TAG_NAME="pr-$(echo "${GITHUB_REF}" | sed 's/refs\/heads\///' | tr '/' '-')"
|
||||
fi
|
||||
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT
|
||||
|
||||
# audit:
|
||||
# name: Security Audit
|
||||
# needs: [detect-project, setup-rust]
|
||||
@@ -171,7 +191,7 @@ jobs:
|
||||
|
||||
docker-build:
|
||||
name: Build and Push Docker Image
|
||||
needs: [detect-project, build]
|
||||
needs: [detect-project, build, set-tag]
|
||||
if: |
|
||||
always() &&
|
||||
needs.detect-project.result == 'success' &&
|
||||
@@ -198,19 +218,6 @@ jobs:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Extract metadata for Docker
|
||||
id: meta
|
||||
run: |
|
||||
if [ "${{ github.ref_type }}" = "tag" ]; then
|
||||
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT
|
||||
elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
|
||||
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$(date +%Y%m%d)" >> $GITHUB_OUTPUT
|
||||
elif [ "${{ github.ref }}" = "refs/heads/development" ]; then
|
||||
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:development,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$(date +%Y%m%d)" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-$(echo ${{ github.ref }} | sed 's/refs\/heads\///' | tr '/' '-')" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Build Docker image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
@@ -219,9 +226,33 @@ jobs:
|
||||
platforms: linux/amd64
|
||||
build-args: |
|
||||
BINARY_NAME=${{ needs.detect-project.outputs.project-name }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.set-tag.outputs.tag_name }}
|
||||
push: true
|
||||
|
||||
tag:
|
||||
name: Create Tag
|
||||
needs: [build, set-tag]
|
||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Git user
|
||||
run: |
|
||||
git config user.name "GitHub Actions"
|
||||
git config user.email "actions@github.com"
|
||||
|
||||
- name: Create and push tag
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
git tag ${{ needs.set-tag.outputs.tag_name }}
|
||||
git push origin ${{ needs.set-tag.outputs.tag_name }}
|
||||
|
||||
|
||||
summary:
|
||||
name: Workflow Summary
|
||||
needs: [test, audit, build, docker-build]
|
||||
|
Reference in New Issue
Block a user