-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (116 loc) · 4.93 KB
/
release-final-boshrelease.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
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
name: Release Bosh Release
on:
workflow_dispatch: { }
push:
branches:
- "main"
tags:
- '**'
env:
RELEASE: "otelcollector-binary"
DESCRIPTION: "OpenTelemetry Collector binary Release"
BOSH_CLI_VERSION: "7.5.5"
permissions: {}
jobs:
build-bosh-release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
ref: ${{ github.ref_name }}
- name: Git config and checkout LFS blobs
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
git lfs checkout
- name: Install Bosh cli and other dependencies
run: |
mkdir -p .bin
wget -nv https://github.com/cloudfoundry/bosh-cli/releases/download/v${BOSH_CLI_VERSION}/bosh-cli-${BOSH_CLI_VERSION}-linux-amd64 -O .bin/bosh
chmod a+x .bin/bosh
echo "$GITHUB_WORKSPACE/.bin" >> $GITHUB_PATH
- name: Create Bosh release
id: boshrelease
run: |
mkdir -p .build
bosh sync-blobs
echo "GITHUB_REF=${GITHUB_REF}"
echo "GITHUB_REF_NAME=${GITHUB_REF_NAME}"
if [[ "${GITHUB_REF#refs/tags/}" =~ ^refs/.* ]]
then
# the trigger does not come from a tag. Not a final version
bosh create-release --tarball="$GITHUB_WORKSPACE/.build/$RELEASE.tgz"
version=$(ls dev_releases/$RELEASE/*.yml | sed 's/.*\/.*-\(.*\)\.yml$/\1/' | sort -t. -k 1,1nr -k 2,2nr | head -1)
echo "type=dev" | tee -a $GITHUB_OUTPUT
else
tag="${GITHUB_REF_NAME}"
if [[ "${tag#v}" =~ ^([0-9]+\.){0,2}(\*|[0-9]+)$ ]]
then
# Tag is a version, create it with this vesion
echo "Using provided version from the tag (tag=$tag)"
bosh create-release --final --tarball="$GITHUB_WORKSPACE/.build/$RELEASE.tgz" --version "${tag#v}"
else
# Tag is not a version, bosh will increase the minor version automatically
echo "Tag does not match version (tag=$tag). Let bosh to calculate the next one"
bosh create-release --final --tarball="$GITHUB_WORKSPACE/.build/$RELEASE.tgz"
fi
version=$(ls releases/$RELEASE/*.yml | sed 's/.*\/.*-\(.*\)\.yml$/\1/' | sort -t. -k 1,1nr -k 2,2nr | head -1)
echo "type=final" | tee -a >> $GITHUB_OUTPUT
fi
echo "version=${version}" | tee -a $GITHUB_OUTPUT
echo "file=$GITHUB_WORKSPACE/.build/$RELEASE.tgz" | tee -a $GITHUB_OUTPUT
echo "release=$RELEASE" | tee -a $GITHUB_OUTPUT
- name: Uploads artifact release
uses: actions/upload-artifact@v4
with:
name: "${{ steps.boshrelease.outputs.release }}-${{ steps.boshrelease.outputs.version }}-boshrelease"
path: ${{ steps.boshrelease.outputs.file }}
- name: Git commit final resources
if: ${{ steps.boshrelease.outputs.type == 'final' }}
run: |
git add .final_builds blobstore releases
message=$(git tag -l --format='%(contents)' "${GITHUB_REF_NAME}")
git commit -m "${message}"
remote=main
[ "${{ github.ref_type }}" == "branch" ] && remote=${{ github.ref_name }}
# This does not trigger another workflow with built-in `GITHUB_TOKEN` secret
git push origin HEAD:${remote}
- name: Generate release notes from git commits
run: |
lastcommit=$(git log --no-walk --tags --pretty="%h %s" | awk 'NR==1{ print $1 }')
git_changes=$(git log --pretty="%h %aI %s (%an)" $lastcommit..@ | sed 's/^/- /')
version="${{ steps.boshrelease.outputs.version }}"
sha1=$(openssl sha1 "${{ steps.boshrelease.outputs.file }}" | awk '{ print $2 }')
cat <<EOF > .build/release-notes.txt
# $RELEASE version $version
$DESCRIPTION
## Changes since last version
$git_changes
## Using in a bosh Deployment
releases:
- name: $RELEASE
url: https://github.com/${GITHUB_REPOSITORY}/releases/download/v${version}/${RELEASE}.tgz
version: '$version'
sha1: $sha1
or to always point to latest release:
releases:
- name: $RELEASE
url: https://github.com/${GITHUB_REPOSITORY}/releases/latest/download/${RELEASE}.tgz
version: latest
EOF
- name: Create a Release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: ${{ steps.boshrelease.outputs.type != 'final' }}
tag_name: "v${{ steps.boshrelease.outputs.version }}"
files: ${{ steps.boshrelease.outputs.file }}
body_path: .build/release-notes.txt
generate_release_notes: true
make_latest: ${{ steps.boshrelease.outputs.type == 'final' }}