This repository was archived by the owner on May 4, 2026. It is now read-only.
forked from CyberCX-STA/PurpleOps
-
Notifications
You must be signed in to change notification settings - Fork 4
83 lines (71 loc) · 2.61 KB
/
Copy pathrelease_build_push.yml
File metadata and controls
83 lines (71 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Create GitHub Release & Docker Build and Push
on:
workflow_dispatch:
jobs:
release-and-build:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
contents: write # Needed to create tags and releases
packages: write # Needed to push to GHCR
id-token: write # For trusted publishing
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Generate tag name from current date
id: date
run: echo "tag=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT
- name: Check if tag already exists
id: check_tag
run: |
if git rev-parse "${{ steps.date.outputs.tag }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create git tag and push using token
if: steps.check_tag.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag ${{ steps.date.outputs.tag }}
git push https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }} ${{ steps.date.outputs.tag }}
- name: Create GitHub Release
if: steps.check_tag.outputs.exists == 'false'
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.date.outputs.tag }}
name: Release ${{ steps.date.outputs.tag }}
generateReleaseNotes: true
draft: false
prerelease: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ steps.date.outputs.tag }},priority=1000
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max