-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (85 loc) · 3.36 KB
/
deploy.yml
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Deploy on Release or Pre-release
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PROJECT_NAME: ahb-tabellen
OCTOPUS_SPACE: Default
on:
release:
types: [published]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set build and release information
id: build_release_info
run: |
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
COMMIT_ID=$(git rev-parse HEAD)
VERSION_TAG=${GITHUB_REF#refs/tags/}
echo "::set-output name=build_date::$BUILD_DATE"
echo "::set-output name=commit_id::$COMMIT_ID"
echo "::set-output name=version_tag::$VERSION_TAG"
echo "::set-output name=prerelease::${{ github.event.release.prerelease }}"
- name: Log in to the Container registry
uses: docker/login-action@v3.3.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.6.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6.10.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILD_DATE=${{ steps.build_release_info.outputs.build_date }}
COMMIT_ID=${{ steps.build_release_info.outputs.commit_id }}
VERSION=${{ steps.build_release_info.outputs.version_tag }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Login to Octopus Deploy 🐙
uses: OctopusDeploy/login@v1
with:
server: https://hochfrequenz.octopus.app
service_account_id: 990f3f62-2e3f-4b1e-9569-d5a6817a2c80
- name: Create a release in Octopus Deploy 🐙
uses: OctopusDeploy/create-release-action@v3
with:
space: ${{ env.OCTOPUS_SPACE }}
project: ${{ env.PROJECT_NAME }}
release_number: ${{ steps.build_release_info.outputs.version_tag }}
git_ref: ${{ github.ref }}
git_commit: ${{ github.sha }}
release_notes: "Release created from GitHub Actions. Version: ${{ steps.build_release_info.outputs.version_tag }}"
- name: Deploy a release in Octopus Deploy 🐙
uses: OctopusDeploy/deploy-release-action@v3
with:
space: ${{ env.OCTOPUS_SPACE }}
project: ${{ env.PROJECT_NAME }}
release_number: ${{ steps.build_release_info.outputs.version_tag }}
environments: |
Staging
- name: Notify for Production Deployment Approval
if: ${{ steps.build_release_info.outputs.prerelease == 'false' }}
run: |
echo "Release ${{ steps.build_release_info.outputs.version_tag }} created. Awaiting manual approval for production deployment."