Publish Agent #45
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: Publish Agent | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: "Manual environment to run (staging | prod)" | |
required: false | |
type: string | |
agent_version: | |
description: "Build version example: v2.0.2" | |
required: true | |
type: string | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: write # This is required for actions/checkout | |
jobs: | |
### SET ENV ### | |
set_env: | |
runs-on: ubuntu-latest | |
name: Set Environment | |
steps: | |
- name: Set environment base on input | |
id: set_env | |
run: echo "Exposing environment vars to reusable workflow" | |
outputs: | |
ENV: ${{ inputs.environment }} | |
### BUILD ### | |
build: | |
name: Build | |
runs-on: ${{ matrix.os }} | |
env: | |
AGENT_VERSION: ${{ inputs.agent_version }} | |
strategy: | |
fail-fast: true | |
matrix: | |
os: | |
- ubuntu-latest | |
- macos-latest | |
- windows-latest | |
node-version: | |
- 14.x | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js ${{ matrix.node-version }} | |
uses: actions/[email protected] | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Cache | |
id: cache-packages | |
uses: actions/[email protected] | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-node${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }} | |
- name: Install packages | |
if: steps.cache-packages.outputs.cache-hit != 'true' | |
run: npm ci | |
- name: Set BUILD_VERSION environment variable | |
run: echo "BUILD_VERSION=$(node -p "require('./package').version")" >> $GITHUB_ENV | |
- name: Build with Node.js ${{ matrix.node-version }} on ${{ runner.os }} | |
env: | |
CI: true | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
run: | | |
npm run buildLinux --if-present | |
chmod +x bin/cli-linux-x64 *.sh | |
ls -l bin | |
sed -i "s/$BUILD_VERSION/$AGENT_VERSION/g" package.json | |
- name: Build with Node.js ${{ matrix.node-version }} on ${{ runner.os }} | |
env: | |
CI: true | |
if: ${{ matrix.os == 'macos-latest' }} | |
run: | | |
npm run buildMacos --if-present | |
chmod +x bin/cli-macos-x64 *.sh | |
ls -l bin | |
sed -i '' "s/$BUILD_VERSION/$AGENT_VERSION/g" package.json | |
- name: Build with Node.js ${{ matrix.node-version }} on ${{ runner.os }} | |
env: | |
CI: true | |
if: ${{ matrix.os == 'windows-latest' }} | |
run: npm run buildWin --if-present | |
- name: Upload Windows x64 artifact | |
uses: actions/upload-artifact@v2 | |
if: ${{ matrix.os == 'windows-latest' }} | |
with: | |
name: katalon-agent-win-x64-${{ env.AGENT_VERSION }} | |
path: | | |
bin/cli-win-x64.exe | |
bin/nssm.exe | |
bin/*.bat | |
- name: Upload Windows x86 artifact | |
uses: actions/upload-artifact@v2 | |
if: ${{ matrix.os == 'windows-latest' }} | |
with: | |
name: katalon-agent-win-x86-${{ env.AGENT_VERSION }} | |
path: | | |
bin/cli-win-x86.exe | |
bin/nssm.exe | |
bin/*.bat | |
- name: Upload Linux x64 artifact | |
uses: actions/upload-artifact@v2 | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
with: | |
name: katalon-agent-linux-x64-${{ env.AGENT_VERSION }} | |
path: | | |
bin/cli-linux-x64 | |
bin/*.sh | |
- name: Upload MacOS x64 artifact | |
uses: actions/upload-artifact@v2 | |
if: ${{ matrix.os == 'macos-latest' }} | |
with: | |
name: katalon-agent-macos-x64-${{ env.AGENT_VERSION }} | |
path: | | |
bin/cli-macos-x64 | |
bin/start.sh | |
### RELEASE ### | |
release: | |
name: Release | |
environment: ${{ needs.set_env.outputs.ENV }} | |
env: | |
AGENT_VERSION: ${{ inputs.agent_version }} | |
needs: [set_env, build] | |
if: ${{ needs.set_env.outputs.ENV == 'prod' }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: | |
- 10.x | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js ${{ matrix.node-version }} | |
uses: actions/[email protected] | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Cache | |
id: cache-packages | |
uses: actions/[email protected] | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-node${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }} | |
- name: Install packages | |
if: steps.cache-packages.outputs.cache-hit != 'true' | |
run: npm ci | |
- name: Download artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
path: . | |
- name: Add execute permission to downloaded artifacts | |
run: chmod +x katalon-agent-linux-*/* katalon-agent-macos-*/* | |
- name: Set BUILD_VERSION environment variable | |
run: echo "BUILD_VERSION=$(node -p "require('./package').version")" >> $GITHUB_ENV | |
- name: Change Package.json version for release | |
run: sed -i "s/$BUILD_VERSION/$AGENT_VERSION/g" package.json | |
- name: Package artifacts for release | |
env: | |
GZIP: -9 | |
run: | | |
set -x | |
mkdir -p packages | |
ls -la | |
zip -9 -j packages/katalon-agent-win-x64-$AGENT_VERSION.zip katalon-agent-win-x64-$AGENT_VERSION/* | |
zip -9 -j packages/katalon-agent-win-x86-$AGENT_VERSION.zip katalon-agent-win-x86-$AGENT_VERSION/* | |
zip -9 -j packages/katalon-agent-linux-x64-$AGENT_VERSION.zip katalon-agent-linux-x64-$AGENT_VERSION/* | |
zip -9 -j packages/katalon-agent-macos-x64-$AGENT_VERSION.zip katalon-agent-macos-x64-$AGENT_VERSION/* | |
cd katalon-agent-linux-x64-$AGENT_VERSION | |
tar cvzf ../packages/katalon-agent-linux-x64-$AGENT_VERSION.tar.gz * | |
- name: Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: npm run release | |
### DEPLOY ### | |
deploy: | |
name: Deploy cloud agent | |
environment: ${{ needs.set_env.outputs.ENV }} | |
env: | |
AGENT_VERSION: ${{ inputs.agent_version }} | |
needs: [set_env, build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js ${{ matrix.node-version }} | |
uses: actions/[email protected] | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Install packages | |
run: npm install --only dev | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/katalon-github-oidc-federation | |
role-session-name: github-actions | |
aws-region: ${{ vars.AWS_REGION }} | |
mask-aws-account-id: 'no' | |
- name: Download artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
path: . | |
- name: Add execute permission to downloaded artifacts | |
run: chmod +x katalon-agent-linux-*/* katalon-agent-macos-*/* | |
- name: Deploy to s3 prod | |
if: ${{ needs.set_env.outputs.ENV == 'prod' }} | |
run: | | |
ls -laR | |
aws s3 cp katalon-agent-linux-x64-*/cli-linux-x64 s3://${{ secrets.AWS_S3_BUCKET }}/katalon-agent/$AGENT_VERSION/cli-linux-x64 | |
commit: | |
runs-on: ubuntu-latest | |
needs: [set_env, build, deploy, release] | |
name: Commit Code | |
env: | |
AGENT_VERSION: ${{ inputs.agent_version }} | |
environment: ${{ needs.set_env.outputs.ENV }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Set BUILD_VERSION environment variable | |
run: echo "BUILD_VERSION=$(node -p "require('./package').version")" >> $GITHUB_ENV | |
- name: Change Package.json version for release | |
run: sed -i "s/$BUILD_VERSION/$AGENT_VERSION/g" package.json | |
### Commit code | |
- name: Deploy to GitOps | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: Update version to ${{ env.AGENT_VERSION }} | |
# Optional commit user and author settings | |
commit_user_name: github-cloudops-bot # defaults to "github-actions[bot]" | |
commit_user_email: [email protected] # defaults to "41898282+github-actions[bot]@users.noreply.github.com" | |
commit_author: Author <[email protected]> # defaults to author of the commit that triggered the run |