Merge pull request #1040 from aziontech/dev #181
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Production | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
container: | |
image: golang:1.22.5 | |
outputs: | |
binver: ${{ steps.binversion.outputs.BIN_VERSION }} | |
env: | |
CGO_ENABLED: 0 # Statically linked | |
steps: | |
- name: Setting GIT | |
run: git config --global url."https://${{ secrets.GLOBAL_TOKEN }}:x-oauth-basic@github.com/aziontech".insteadOf "https://github.com/aziontech" | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setting up a secure repository | |
run: git config --global --add safe.directory /__w/azion/azion | |
# - name: Bump version and push tag | |
# id: tag_ver | |
# uses: anothrNick/github-tag-action@1.37.0 | |
# env: | |
# RELEASE_BRANCHES: main | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Refresh git | |
run: git fetch --tags | |
- name: Build | |
env: | |
STORAGE_API: ${{ secrets.STORAGE_API_STAGE }} | |
run: make build ENVFILE=./env/prod | |
- name: Cross-build | |
env: | |
STORAGE_API: ${{ secrets.STORAGE_API_STAGE }} | |
run: make cross-build ENVFILE=./env/prod | |
- name: Install AWS CLI | |
run: | | |
apt update | |
apt install -y awscli | |
- name: Configure AWS Credentials (azion-downloads) | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.CLI_S3_DOWNLOADS_ID }} | |
aws-secret-access-key: ${{ secrets.CLI_S3_DOWNLOADS_SECRET }} | |
aws-region: us-east-1 | |
- name: Upload to azion-downloads production dir | |
run: | | |
while read spec; \ | |
do\ | |
distro=$(echo ${spec} | cut -d/ -f1);\ | |
goarch=$(echo ${spec} | cut -d/ -f2);\ | |
arch=$(echo ${goarch} | sed 's/386/x86_32/g; s/amd64/x86_64/g; s/arm$/arm32/g;');\ | |
cp dist/$distro/$arch/azion* dist/$distro/$arch/azion; | |
aws s3 cp --no-progress --recursive \ | |
--exclude "*" --include "azion*" \ | |
dist/$distro/$arch/ s3://azion-downloads/$distro/$arch/; \ | |
done < BUILD | |
- id: binversion | |
run: echo "BIN_VERSION=$(git describe --tags)" >> $GITHUB_OUTPUT | |
- name: set bin version to github env | |
run: echo "BIN_VERSION=$(git describe --tags)" >> $GITHUB_ENV | |
# - uses: goreleaser/goreleaser-action@v6 | |
# with: | |
# distribution: goreleaser | |
# version: 2.3.2 | |
# args: release --clean | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} | |
# API_URL: https://api.azionapi.net | |
# STORAGE_URL: https://api.azion.com | |
# AUTH_URL: https://sso.azion.com/api | |
# TEMPLATE_BRANCH: main | |
# SEGMENT_KEY: Irg63QfdvWpoANAVeCBEwfxXBKvoSSzt | |
# CHOCOLATEY_TOKEN: ${{ secrets.CHOCO_TOKEN }} | |
# bump_formula: | |
# runs-on: ubuntu-latest | |
# needs: build | |
# steps: | |
# - uses: dawidd6/action-homebrew-bump-formula@v3 | |
# with: | |
# token: ${{secrets.RELEASE_GITHUB_TOKEN}} | |
# formula: azion | |
# tag: ${{needs.build.outputs.binver}} | |
publish-choco-package: | |
runs-on: windows-latest | |
needs: build | |
steps: | |
# Step 1: Check out the code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Step 2: Set up Chocolatey | |
- name: Set up Chocolatey | |
run: | | |
Set-ExecutionPolicy Bypass -Scope Process -Force | |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 | |
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression | |
# Step 3: Update version in azion.nuspec | |
- name: Update version in azion.nuspec | |
run: | | |
$version = '${{ needs.build.outputs.binver }}' | |
if (-Not $version) { | |
Write-Error "Version is not defined! Check the output from bump_formula." | |
exit 1 | |
} | |
Write-Host "Updating nuspec version to $version" | |
(Get-Content chocolatey/azion.nuspec) -replace '<version>.*</version>', "<version>$version</version>" | Set-Content chocolatey/azion.nuspec | |
shell: pwsh | |
# Step 4: Download the Azion executable | |
- name: Download Azion executable | |
run: | | |
$toolsDir = "$(Resolve-Path .\chocolatey\tools)" | |
New-Item -ItemType Directory -Force -Path $toolsDir | Out-Null | |
$outputFile = Join-Path $toolsDir 'azion.exe' | |
$url = 'http://downloads.azion.com/windows/x86_64/azion' | |
Invoke-WebRequest -Uri $url -OutFile $outputFile | |
shell: pwsh | |
# Step 5: Calculate checksum | |
- name: Calculate checksum | |
id: calculate-checksum | |
run: | | |
$outputFile = "$(Resolve-Path .\chocolatey\tools\azion.exe)" | |
$checksum = (Get-FileHash -Path $outputFile -Algorithm SHA256).Hash | |
echo "::set-output name=checksum::$checksum" | |
shell: pwsh | |
# Step 6: Replace checksum in chocolateyinstall.ps1 | |
- name: Replace checksum in chocolateyinstall.ps1 | |
run: | | |
(Get-Content .\chocolatey\tools\chocolateyinstall.ps1) -replace '{{CHECKSUM}}', '${{ steps.calculate-checksum.outputs.checksum }}' | Set-Content .\chocolatey\tools\chocolateyinstall.ps1 | |
shell: pwsh | |
# Step 7: Pack and push the Chocolatey package | |
- name: Publish Chocolatey package | |
env: | |
CHOCO_API_KEY: ${{ secrets.CHOCO_TOKEN }} | |
run: | | |
# Ensure that the Chocolatey package is packed and pushed correctly | |
choco pack chocolatey/azion.nuspec | |
Write-Host "Listing files created by choco pack" | |
Get-ChildItem -Force | Format-Table | |
choco push D:\a\azion\azion\azion.${{ needs.build.outputs.binver }}.nupkg --source https://push.chocolatey.org/ --api-key $env:CHOCO_API_KEY | |
shell: pwsh | |
Publish-to-WinGet: | |
runs-on: windows-latest | |
needs: build | |
steps: | |
- uses: vedantmgoyal9/winget-releaser@main | |
with: | |
identifier: azion.azion | |
installers-regex: '\.exe$' # Only `.exe` files | |
token: ${{ secrets.RELEASE_GITHUB_TOKEN }} | |