forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (127 loc) · 5 KB
/
Copy pathpublish_release.yml
File metadata and controls
153 lines (127 loc) · 5 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Generate Release Notes and Deploy Production to Azure
on:
push:
branches:
- master
- main
workflow_dispatch:
permissions:
contents: write
jobs:
release:
if: github.repository == 'criani/CIPP-API' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
name: Generate Release Notes and Deploy to Azure
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Read and Trim Version
id: get_version
run: |
if [ ! -f version_latest.txt ]; then
echo "Error: version_latest.txt not found!"
exit 1
fi
VERSION=$(cat version_latest.txt | tr -d '[:space:]')
if [ -z "$VERSION" ]; then
echo "Error: version_latest.txt is empty after trimming!"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Check if Tag Exists
id: tag_check
run: |
git fetch --tags
if git rev-parse "refs/tags/${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
echo "tag_exists=true" >> $GITHUB_ENV
echo "Tag ${{ steps.get_version.outputs.version }} already exists. Skipping release creation."
else
echo "tag_exists=false" >> $GITHUB_ENV
echo "Tag ${{ steps.get_version.outputs.version }} does not exist. Release will be created."
fi
- name: Get Previous Tag
id: previous_tag
if: env.tag_exists == 'false'
run: |
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "previous_tag=$PREV_TAG" >> $GITHUB_OUTPUT
echo "Previous tag: $PREV_TAG"
- name: Generate Release Notes
id: changelog
if: env.tag_exists == 'false'
uses: actions/github-script@v7
with:
script: |
const params = {
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ steps.get_version.outputs.version }}',
target_commitish: context.sha
};
const previousTag = '${{ steps.previous_tag.outputs.previous_tag }}';
if (previousTag) {
params.previous_tag_name = previousTag;
}
const { data } = await github.rest.repos.generateReleaseNotes(params);
core.setOutput('changelog', data.body);
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
if: env.tag_exists == 'false'
uses: ncipollo/release-action@v1.14.0
with:
tag: ${{ steps.get_version.outputs.version }}
name: "v${{ steps.get_version.outputs.version }}"
draft: false
prerelease: false
makeLatest: true
body: ${{ steps.changelog.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create version.json
run: |
VERSION=$(cat version_latest.txt | tr -d '[:space:]')
SHORT_SHA="${GITHUB_SHA::7}"
echo "{\"version\": \"${VERSION}\", \"commit\": \"${SHORT_SHA}\"}" > version.json
cat version.json
- name: Build and stage modules
shell: pwsh
run: ./Tools/Build-DevApiModules.ps1
- name: Prepare and Zip Release Files
run: |
mkdir -p src/releases
zip -r src/releases/latest.zip . \
--exclude "./src/releases/*" \
--exclude ".git/*" \
--exclude ".github/*" \
--exclude ".gitignore" \
--exclude ".gitattributes"
- name: Verify Zip Contents
run: |
echo "Checking version_latest.txt inside zip:"
unzip -p src/releases/latest.zip version_latest.txt
echo "Checking host.json exists at zip root:"
unzip -l src/releases/latest.zip | grep -E "^[^/]*[[:space:]]+[0-9-]+[[:space:]]+[0-9:]+[[:space:]]+host.json$|host.json"
echo "Checking package size:"
ls -lh src/releases/latest.zip
- name: Azure Blob Upload with Destination folder defined
uses: LanceMcCarthy/Action-AzureBlobUpload@v3.3.0
with:
connection_string: ${{ secrets.AZURE_CONNECTION_STRING }}
container_name: cipp-api
source_folder: src/releases/
destination_folder: /
delete_if_exists: true
- name: Deploy Zip to Azure Function App
uses: Azure/functions-action@v1
with:
app-name: prospectorcipp62evl
package: src/releases/latest.zip
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
- name: Deployment Summary
run: |
echo "Deployed CIPP API version ${{ steps.get_version.outputs.version }} to prospectorcipp62evl"
echo "Package: src/releases/latest.zip"