-
Notifications
You must be signed in to change notification settings - Fork 10
162 lines (160 loc) · 7.14 KB
/
release.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# ------------------------------------------------------------
# Copyright 2021 The Dapr Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------
name: release
on:
workflow_dispatch:
repository_dispatch:
types: update
schedule:
- cron: '0 * * * *'
jobs:
build:
name: Build ${{ matrix.target_os }}_${{ matrix.target_arch }} binaries
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macOS-latest]
target_arch: [amd64]
include:
- os: macOS-latest
target_os: darwin
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Check Homebrew installation
run: brew help
- name: Create artifact directory
run: mkdir -p release && touch release/version.txt
- name: Fetch latest released version for Dapr Cli.
env:
GITHUB_TOKEN: ${{ secrets.DAPR_BOT_TOKEN }}
run: |
DAPR_CLI_VERSION=$( curl -s -f "https://x-access-token:${GITHUB_TOKEN}@api.github.com/repos/dapr/cli/releases" | grep \"tag_name\" | awk 'NR==1{print $2}' | sed -n 's/\"v\(.*\)\",/\1/p' )
echo "Found version ${DAPR_CLI_VERSION}"
echo "DAPR_CLI_VERSION=$DAPR_CLI_VERSION" >> $GITHUB_ENV
- name: Generate filename.
run: |
FORMULA_FILENAME=$( bash ./.github/scripts/generate-filename.sh )
echo "FORMULA_FILENAME=$FORMULA_FILENAME" >> $GITHUB_ENV
- name: Generate formula name.
run: |
FORMULA_NAME=$( bash ./.github/scripts/generate-formula-name.sh )
echo "FORMULA_NAME=$FORMULA_NAME" >> $GITHUB_ENV
- name: Generate formula name.
run: |
FORMULA_CLASSNAME=$( bash ./.github/scripts/generate-formula-classname.sh )
echo "FORMULA_CLASSNAME=$FORMULA_CLASSNAME" >> $GITHUB_ENV
- name: Check if Dapr Cli's version is new.
run: |
NEW_VERSION=$( cat ${FORMULA_FILENAME} | grep "version " | grep "'${DAPR_CLI_VERSION}'" &> /dev/null || echo "yes" )
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Get Dapr Cli's source code tarball's shasum.
env:
GITHUB_TOKEN: ${{ secrets.DAPR_BOT_TOKEN }}
if: env.NEW_VERSION == 'yes'
run: |
DAPR_CLI_SRC_SHASUM=$( curl -L -f "https://x-access-token:${GITHUB_TOKEN}@github.com/dapr/cli/archive/v${DAPR_CLI_VERSION}.tar.gz" 2> /dev/null | shasum -a 256 | cut -d\- -f1 | xargs -I {} echo {} )
echo "DAPR_CLI_SRC_SHASUM=$DAPR_CLI_SRC_SHASUM" >> $GITHUB_ENV
- name: Get Homebrew's tap for Dapr Cli.
if: env.NEW_VERSION == 'yes'
run: brew tap dapr/tap && brew update
- name: Generating initial formula for new version.
if: env.NEW_VERSION == 'yes'
run: bash ./.github/scripts/generate-temp-formula.sh
- name: Setup Go
if: env.NEW_VERSION == 'yes'
run: |
brew unlink [email protected] || echo "Could not unlink [email protected]"
# Go might fail just to symlink.
brew install go || echo "Installing Go might have failed"
brew link --overwrite go
go version
- name: Generating Homebrew's bottle file for Dapr Cli.
if: env.NEW_VERSION == 'yes'
run: |
brew install ${{ env.FORMULA_NAME }} --build-bottle && brew bottle ${{ env.FORMULA_NAME }}
generated_bottle_filename=$( ls -1 *.bottle.*tar.gz )
bottle_filename=$( echo $generated_bottle_filename | sed -e 's/--/-/' | sed -e 's/\.1\.tar.gz/.tar.gz/' )
DAPR_CLI_BOTTLE_OS_VERSION=$( echo $generated_bottle_filename | sed -e 's/--/-/' | sed -e 's/.*\.\(.*\)\.bottle.*/\1/' )
mv $generated_bottle_filename $bottle_filename
DAPR_CLI_BOTTLE_SHASUM=$( shasum -a 256 ${bottle_filename} | sed -n "s/\(.*\) ${bottle_filename}/\1/p" | xargs -I {} echo {} )
mkdir -p release
mv $bottle_filename release/$bottle_filename
echo ${DAPR_CLI_VERSION} > release/version.txt
echo "DAPR_CLI_BOTTLE_OS_VERSION=$DAPR_CLI_BOTTLE_OS_VERSION" >> $GITHUB_ENV
echo "DAPR_CLI_BOTTLE_SHASUM=$DAPR_CLI_BOTTLE_SHASUM" >> $GITHUB_ENV
- name: Generating initial formula for new version.
if: env.NEW_VERSION == 'yes'
run: bash ./.github/scripts/generate-formula.sh
- name: Release artifacts
uses: actions/upload-artifact@master
with:
name: bottle_drop
path: ./release
- name: Commit to repository
if: env.NEW_VERSION == 'yes'
env:
GITHUB_TOKEN: ${{ secrets.DAPR_BOT_TOKEN }}
COMMIT_MSG: |
Updating ${{ env.FORMULA_NAME }} formula for version ${{ env.DAPR_CLI_VERSION }}
skip-checks: true
run: |
git config user.email "Dapr Bot"
git config user.name "[email protected]"
# Update origin with token
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
# Checkout the branch so we can push back to it
git checkout master
git fetch origin
git add .
# Only commit and push if we have changes
git diff --quiet && git diff --staged --quiet || (git commit -m "${COMMIT_MSG}"; git pull --rebase; git push origin master)
git tag v${{env.DAPR_CLI_VERSION}}
git push origin --tags
publish:
name: Publish binaries
needs: build
env:
ARTIFACT_DIR: ./release
runs-on: ubuntu-latest
steps:
- name: download artifacts
uses: actions/download-artifact@master
with:
name: bottle_drop
path: ${{ env.ARTIFACT_DIR }}
- name: Set Release Version
run: |
REL_VERSION_FILE="${{ env.ARTIFACT_DIR }}/version.txt"
REL_VER=`cat ${REL_VERSION_FILE}`
echo "REL_VERSION=${REL_VER}" >> $GITHUB_ENV
rm -f ${REL_VERSION_FILE}
- name: publish binaries to github
if: env.REL_VERSION != ''
env:
GITHUB_TOKEN: ${{ secrets.DAPR_BOT_TOKEN }}
run: |
echo "installing github-release-cli..."
sudo npm install --slient --no-progress -g [email protected]
# Get the list of files
RELEASE_ARTIFACT=(${ARTIFACT_DIR}/*)
# Parse repository to get owner and repo names
OWNER_NAME="${GITHUB_REPOSITORY%%/*}"
REPO_NAME="${GITHUB_REPOSITORY#*/}"
echo "Uploading Dapr CLI Binaries to GitHub Release"
github-release upload \
--owner $OWNER_NAME --repo $REPO_NAME \
--tag "v${REL_VERSION}" \
--name "Dapr CLI v${REL_VERSION}" \
--prerelease false \
${RELEASE_ARTIFACT[*]}