|
| 1 | +name: AWS |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +env: |
| 7 | + AWS_BUCKET_NAME: ${{ secrets.AWS_BUCKET_NAME }} |
| 8 | + AWS_DISTRIBUTION_ID: ${{ secrets.AWS_DISTRIBUTION_ID }} |
| 9 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 10 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 11 | + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + release-private: |
| 15 | + name: Release s3 private |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Download All Artifacts |
| 21 | + uses: actions/download-artifact@v4 |
| 22 | + with: |
| 23 | + path: ./release |
| 24 | + |
| 25 | + - run: ls -R ./release |
| 26 | + |
| 27 | + - name: Publish private |
| 28 | + run: | |
| 29 | +
|
| 30 | + # Define array of folders to exclude |
| 31 | + exclude=("web" "web-mini" "redisstack" "docker") |
| 32 | +
|
| 33 | + # Iterate through first-level directories in ./release |
| 34 | + for dir in ./release/*/; do |
| 35 | + dir_name=$(basename "$dir") |
| 36 | +
|
| 37 | + # Check if the directory is not in the exclude list |
| 38 | + if [[ ! " ${exclude[@]} " =~ " ${dir_name} " ]]; then |
| 39 | + # Move all files from the subdirectory to the release directory |
| 40 | + mv "$dir"* ./release/ |
| 41 | +
|
| 42 | + # Remove the now-empty subdirectory |
| 43 | + rmdir "$dir" |
| 44 | + fi |
| 45 | + done |
| 46 | +
|
| 47 | + chmod +x .circleci/build/sum_sha256.sh |
| 48 | + .circleci/build/sum_sha256.sh |
| 49 | + applicationVersion=$(jq -r '.version' redisinsight/package.json) |
| 50 | +
|
| 51 | + aws s3 cp release/ s3://${AWS_BUCKET_NAME}/private/${applicationVersion} --recursive |
| 52 | +
|
| 53 | + release-public: |
| 54 | + name: Release s3 public |
| 55 | + runs-on: ubuntu-latest |
| 56 | + needs: 'release-private' |
| 57 | + environment: 'production-approve' |
| 58 | + steps: |
| 59 | + - uses: actions/checkout@v4 |
| 60 | + |
| 61 | + - name: Init variables |
| 62 | + run: | |
| 63 | + latestYmlFileName="latest.yml" |
| 64 | + downloadLatestFolderPath="public/latest" |
| 65 | + upgradeLatestFolderPath="public/upgrades" |
| 66 | + releasesFolderPath="public/releases" |
| 67 | + appName=$(jq -r '.productName' electron-builder.json) |
| 68 | + appVersion=$(jq -r '.version' redisinsight/package.json) |
| 69 | +
|
| 70 | + echo "downloadLatestFolderPath=${downloadLatestFolderPath}" >> $GITHUB_ENV |
| 71 | + echo "upgradeLatestFolderPath=${upgradeLatestFolderPath}" >> $GITHUB_ENV |
| 72 | + echo "releasesFolderPath=${releasesFolderPath}" >> $GITHUB_ENV |
| 73 | + echo "applicationName=${appName}" >> $GITHUB_ENV |
| 74 | + echo "applicationVersion=${appVersion}" >> $GITHUB_ENV |
| 75 | + echo "appFileName=Redis-Insight" >> $GITHUB_ENV |
| 76 | +
|
| 77 | + # download latest.yml file to get last public version |
| 78 | + aws s3 cp s3://${AWS_BUCKET_NAME}/${downloadLatestFolderPath}/${latestYmlFileName} . |
| 79 | +
|
| 80 | + versionLine=$(head -1 ${latestYmlFileName}) |
| 81 | + versionLineArr=(${versionLine/:// }) |
| 82 | + previousAppVersion=${versionLineArr[1]} |
| 83 | +
|
| 84 | + echo "previousApplicationVersion=${previousAppVersion}" >> $GITHUB_ENV |
| 85 | +
|
| 86 | + - name: Publish AWS S3 |
| 87 | + run: | |
| 88 | +
|
| 89 | + # check if sub directories exists |
| 90 | + if [[ -z "$downloadLatestFolderPath" || -z "$upgradeLatestFolderPath" ]]; then |
| 91 | + exit 1; |
| 92 | + fi |
| 93 | + # remove previous build from the latest directory /public/latest |
| 94 | + aws s3 rm s3://${AWS_BUCKET_NAME}/${downloadLatestFolderPath} --recursive |
| 95 | +
|
| 96 | + # remove previous build from the upgrade directory /public/upgrades |
| 97 | + aws s3 rm s3://${AWS_BUCKET_NAME}/${upgradeLatestFolderPath} --recursive |
| 98 | +
|
| 99 | + # copy current version apps for download to /public/latest |
| 100 | + aws s3 cp s3://${AWS_BUCKET_NAME}/private/${applicationVersion}/ \ |
| 101 | + s3://${AWS_BUCKET_NAME}/${downloadLatestFolderPath} --recursive --exclude "*.zip" |
| 102 | +
|
| 103 | + # copy current version apps for upgrades to /public/upgrades |
| 104 | + aws s3 cp s3://${AWS_BUCKET_NAME}/private/${applicationVersion}/ \ |
| 105 | + s3://${AWS_BUCKET_NAME}/${upgradeLatestFolderPath} --recursive |
| 106 | +
|
| 107 | + # !MOVE current version apps to releases folder /public/releases |
| 108 | + aws s3 mv s3://${AWS_BUCKET_NAME}/private/${applicationVersion}/ \ |
| 109 | + s3://${AWS_BUCKET_NAME}/${releasesFolderPath}/${applicationVersion} --recursive |
| 110 | +
|
| 111 | + # invalidate cloudfront cash |
| 112 | + aws cloudfront create-invalidation --distribution-id ${AWS_DISTRIBUTION_ID} --paths "/*" |
| 113 | +
|
| 114 | + - name: Add tags for all objects and create S3 metrics |
| 115 | + run: | |
| 116 | +
|
| 117 | + # declare all tags |
| 118 | + declare -A tag0=( |
| 119 | + [arch]='x64' |
| 120 | + [platform]='macos' |
| 121 | + [objectDownload]=${appFileName}'-mac-x64.dmg' |
| 122 | + [objectUpgrade]=${appFileName}'-mac-x64.zip' |
| 123 | + ) |
| 124 | +
|
| 125 | + declare -A tag1=( |
| 126 | + [arch]='arm64' |
| 127 | + [platform]='macos' |
| 128 | + [objectDownload]=${appFileName}'-mac-arm64.dmg' |
| 129 | + [objectUpgrade]=${appFileName}'-mac-arm64.zip' |
| 130 | + ) |
| 131 | +
|
| 132 | + declare -A tag2=( |
| 133 | + [arch]='x64' |
| 134 | + [platform]='windows' |
| 135 | + [objectDownload]=${appFileName}'-win-installer.exe' |
| 136 | + ) |
| 137 | +
|
| 138 | + declare -A tag3=( |
| 139 | + [arch]='x64' |
| 140 | + [platform]='linux_AppImage' |
| 141 | + [objectDownload]=${appFileName}'-linux-x86_64.AppImage' |
| 142 | + ) |
| 143 | +
|
| 144 | + declare -A tag4=( |
| 145 | + [arch]='x64' |
| 146 | + [platform]='linux_deb' |
| 147 | + [objectDownload]=${appFileName}'-linux-amd64.deb' |
| 148 | + ) |
| 149 | +
|
| 150 | + declare -A tag5=( |
| 151 | + [arch]='x64' |
| 152 | + [platform]='linux_rpm' |
| 153 | + [objectDownload]=${appFileName}'-linux-x86_64.rpm' |
| 154 | + ) |
| 155 | +
|
| 156 | + # loop for add all tags to each app and create metrics |
| 157 | + declare -n tag |
| 158 | + for tag in ${!tag@}; do |
| 159 | +
|
| 160 | + designation0="downloads" |
| 161 | + designation1="upgrades" |
| 162 | +
|
| 163 | + id0="${tag[platform]}_${tag[arch]}_${designation0}_${applicationVersion}" |
| 164 | + id1="${tag[platform]}_${tag[arch]}_${designation1}_${applicationVersion}" |
| 165 | +
|
| 166 | + # add tags to each app for download |
| 167 | + aws s3api put-object-tagging \ |
| 168 | + --bucket ${AWS_BUCKET_NAME} \ |
| 169 | + --key ${downloadLatestFolderPath}/${tag[objectDownload]} \ |
| 170 | + --tagging '{"TagSet": [{ "Key": "version", "Value": "'"${applicationVersion}"'" }, {"Key": "platform", "Value": "'"${tag[platform]}"'"}, {"Key": "arch", "Value": "'"${tag[arch]}"'"}, { "Key": "designation", "Value": "'"${designation0}"'" }]}' |
| 171 | +
|
| 172 | + # add tags to each app for upgrades |
| 173 | + aws s3api put-object-tagging \ |
| 174 | + --bucket ${AWS_BUCKET_NAME} \ |
| 175 | + --key ${upgradeLatestFolderPath}/${tag[objectUpgrade]:=${tag[objectDownload]}} \ |
| 176 | + --tagging '{"TagSet": [{ "Key": "version", "Value": "'"${applicationVersion}"'" }, {"Key": "platform", "Value": "'"${tag[platform]}"'"}, {"Key": "arch", "Value": "'"${tag[arch]}"'"}, { "Key": "designation", "Value": "'"${designation1}"'" }]}' |
| 177 | +
|
| 178 | + # Create metrics for all tags for downloads to S3 |
| 179 | + aws s3api put-bucket-metrics-configuration \ |
| 180 | + --bucket ${AWS_BUCKET_NAME} \ |
| 181 | + --id ${id0} \ |
| 182 | + --metrics-configuration '{"Id": "'"${id0}"'", "Filter": {"And": {"Tags": [{"Key": "platform", "Value": "'"${tag[platform]}"'"}, {"Key": "arch", "Value": "'"${tag[arch]}"'"}, {"Key": "designation", "Value": "'"${designation0}"'"}, {"Key": "version", "Value": "'"${applicationVersion}"'"} ]}}}' |
| 183 | +
|
| 184 | + # Create metrics for all tags for upgrades to S3 |
| 185 | + aws s3api put-bucket-metrics-configuration \ |
| 186 | + --bucket ${AWS_BUCKET_NAME} \ |
| 187 | + --id ${id1} \ |
| 188 | + --metrics-configuration '{"Id": "'"${id1}"'", "Filter": {"And": {"Tags": [{"Key": "platform", "Value": "'"${tag[platform]}"'"}, {"Key": "arch", "Value": "'"${tag[arch]}"'"}, {"Key": "designation", "Value": "'"${designation1}"'"}, {"Key": "version", "Value": "'"${applicationVersion}"'"}]}}}' |
| 189 | +
|
| 190 | + done |
0 commit comments