Skip to content

Commit

Permalink
Switch to trigger-jenkins-job action
Browse files Browse the repository at this point in the history
  • Loading branch information
jcobarreto committed Dec 26, 2023
1 parent 22a586c commit 8063a09
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 147 deletions.
116 changes: 64 additions & 52 deletions create-jira-deployment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ description: |
envInputs:
JENKINS_USER: Jenkins user
JENKINS_BUILD_TOKEN: Jenkins build token. Keep in mind that tokens for `temploy` and `staging` differ
PROXY: Proxy to use for Jenkins
inputs:
token:
# token:
# required: true
# description: 'GitHub token to create a deployment'
jenkins_build_url:
description: 'Jenkins build instance URL'
required: true
jenkins_build_user:
description: 'Jenkins build user'
required: true
jenkins_build_token:
description: 'Jenkins build token'
required: true
jenkins_sa_credentials:
description: 'Jenkins service account credentials to use with IAP'
required: true
description: 'GitHub token to create a deployment'
environment-url:
required: false
description: 'URL of the environment'
Expand All @@ -30,64 +41,65 @@ inputs:
default: 'false'
description: Creates a Github Deployment along with JIRA Deployment


runs:
using: composite
steps:
- uses: chrnorm/deployment-action@v2
name: Create GitHub deployment
id: gh-deployment
if: ${{ always() && inputs.create-gh-deployment == 'true' }}
with:
token: ${{ inputs.token }}
environment-url: ${{ inputs.environment-url }}
environment: ${{ inputs.environment }}
transient-environment: ${{ inputs.transient-environment }}
auto-inactive: ${{ inputs.auto-inactive }}
# - uses: chrnorm/deployment-action@v2
# name: Create GitHub deployment
# id: gh-deployment
# if: ${{ always() && inputs.create-gh-deployment == 'true' }}
# with:
# token: ${{ inputs.token }}
# environment-url: ${{ inputs.environment-url }}
# environment: ${{ inputs.environment }}
# transient-environment: ${{ inputs.transient-environment }}
# auto-inactive: ${{ inputs.auto-inactive }}

- name: Update deployment status on success
if: ${{ success() && inputs.create-gh-deployment == 'true' }}
uses: chrnorm/deployment-status@v2
with:
token: ${{ inputs.token }}
environment-url: ${{ steps.gh-deployment.outputs.environment_url }}
deployment-id: ${{ steps.gh-deployment.outputs.deployment_id }}
log-url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: 'success'
# - name: Update deployment status on success
# if: ${{ success() && inputs.create-gh-deployment == 'true' }}
# uses: chrnorm/deployment-status@v2
# with:
# token: ${{ inputs.token }}
# environment-url: ${{ steps.gh-deployment.outputs.environment_url }}
# deployment-id: ${{ steps.gh-deployment.outputs.deployment_id }}
# log-url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
# state: 'success'

- name: Update deployment status on failure
if: ${{ failure() && inputs.create-gh-deployment == 'true' }}
uses: chrnorm/deployment-status@v2
with:
token: ${{ inputs.token }}
environment-url: ${{ steps.gh-deployment.outputs.environment_url }}
deployment-id: ${{ steps.gh-deployment.outputs.deployment_id }}
log-url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: 'failure'
# - name: Update deployment status on failure
# if: ${{ failure() && inputs.create-gh-deployment == 'true' }}
# uses: chrnorm/deployment-status@v2
# with:
# token: ${{ inputs.token }}
# environment-url: ${{ steps.gh-deployment.outputs.environment_url }}
# deployment-id: ${{ steps.gh-deployment.outputs.deployment_id }}
# log-url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
# state: 'failure'

- name: Set appName
id: repo
if: ${{ always() }}
shell: bash
run: |
echo APP_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2) >> $GITHUB_OUTPUT
# - name: Set appName
# id: repo
# if: ${{ always() }}
# shell: bash
# run: |
# echo APP_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2) >> $GITHUB_OUTPUT

- id: sha
uses: toptal/davinci-github-actions/get-workflow-sha@master
# - id: sha
# uses: toptal/davinci-github-actions/get-workflow-sha@master

- name: Trigger `Create JIRA` deployment
uses: toptal/jenkins-job[email protected]
uses: toptal/actions/trigger-jenkins-job@main
if: ${{ always() }}
with:
jenkins_url: https://jenkins-build.toptal.net/
jenkins_user: ${{ env.JENKINS_USER }}
jenkins_token: ${{ env.JENKINS_BUILD_TOKEN }}
proxy: ${{ env.PROXY }}
job_name: create-jira-deployment
job_params: |
{
"appName": "${{ steps.repo.outputs.APP_NAME }}",
"envName": "${{ inputs.environment }}",
"sha": "${{ github.event.pull_request.head.sha || steps.sha.outputs.result }}"
}
jenkins_url: ${{ inputs.jenkins_build_url }}
jenkins_user: ${{ inputs.jenkins_build_user }}
jenkins_token: ${{ inputs.jenkins_build_token }}
jenkins_client_id: ${{ inputs.jenkins_client_id }}
jenkins_sa_credentials: ${{ inputs.jenkins_sa_credentials }}
# job_name: create-jira-deployment
# job_params: |
# {
# "appName": "${{ steps.repo.outputs.APP_NAME }}",
# "envName": "${{ inputs.environment }}",
# "sha": "${{ github.event.pull_request.head.sha || steps.sha.outputs.result }}"
# }
job_name: job-test-iap
job_timeout: '3600'
208 changes: 113 additions & 95 deletions deploy-storybook/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ description: |
GCR_ACCOUNT_KEY: Necessary token to push image to Google cloud
GCR_GQL_SCHEMAS_BUCKET_TOKEN: Necessary token to pull GQL schema from Google Cloud
JENKINS_DEPLOY_TOKEN: Jenkins deployment token. Keep in mind that tokens for `temploy` and `staging` differ
NPM_TOKEN: Necessary token to install private dependencies
NPM_TOKEN: Necessary token to install private dependencies
inputs:
jenkins_url:
description: 'Jenkins main instance URL'
required: true
jenkins_user:
description: 'Jenkins main user'
required: true
jenkins_token:
description: 'Jenkins main token'
required: true
jenkins_sa_credentials:
description: 'Jenkins service account credentials to use with IAP'
required: true
sha:
description: Commit hash that will be used as a tag for the Docker image
required: true
Expand Down Expand Up @@ -50,133 +62,139 @@ inputs:
pr-number:
description: Event number of the original pr, in case event number or issue number is not present. .
required: false
default: false
default: 'false'
checkout-token:
description: Repository checkout access token `GITHUB_TOKEN`. Required for self hosted runners
required: false
node-version:
required: false
default: 18
default: '18'
description: 'Node.js version used. The action is guaranteed to work only with Node.js@18 (default value)'

runs:
using: composite
steps:
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
# - name: Set up node
# uses: actions/setup-node@v3
# with:
# node-version: ${{ inputs.node-version }}

- name: Install Dependencies
if: ${{ inputs.use-prebuilt-package == 'false' && inputs.use-prebuilt-image == 'false' }}
uses: toptal/davinci-github-actions/[email protected]
with:
checkout-token: ${{ inputs.checkout-token }}
# - name: Install Dependencies
# if: ${{ inputs.use-prebuilt-package == 'false' && inputs.use-prebuilt-image == 'false' }}
# uses: toptal/davinci-github-actions/[email protected]
# with:
# checkout-token: ${{ inputs.checkout-token }}

- name: Generate Types
if: ${{ inputs.generate-types-command != 'false' }}
uses: toptal/davinci-github-actions/[email protected]
with:
generate-types-command: ${{ inputs.generate-types-command }}
gcr-gql-schemas-bucket-token: ${{ env.GCR_GQL_SCHEMAS_BUCKET_TOKEN }}
# - name: Generate Types
# if: ${{ inputs.generate-types-command != 'false' }}
# uses: toptal/davinci-github-actions/[email protected]
# with:
# generate-types-command: ${{ inputs.generate-types-command }}
# gcr-gql-schemas-bucket-token: ${{ env.GCR_GQL_SCHEMAS_BUCKET_TOKEN }}

- name: Build Storybook
if: ${{ inputs.use-prebuilt-package == 'false' && inputs.use-prebuilt-image == 'false' }}
shell: bash
env:
BUILD_COMMAND: ${{ inputs.build-command }}
run: yarn "$BUILD_COMMAND"
# - name: Build Storybook
# if: ${{ inputs.use-prebuilt-package == 'false' && inputs.use-prebuilt-image == 'false' }}
# shell: bash
# env:
# BUILD_COMMAND: ${{ inputs.build-command }}
# run: yarn "$BUILD_COMMAND"

- name: Specify Repository, Jenkins folder and Release Name
id: repo
shell: bash
env:
FOLDER_NAME: ${{ inputs.jenkins-folder-name }}
EVENT_NUMBER: ${{ github.event.number || github.event.issue.number || inputs.pr-number }}
run: |
folder_name=$FOLDER_NAME
# - name: Specify Repository, Jenkins folder and Release Name
# id: repo
# shell: bash
# env:
# FOLDER_NAME: ${{ inputs.jenkins-folder-name }}
# EVENT_NUMBER: ${{ github.event.number || github.event.issue.number || inputs.pr-number }}
# run: |
# folder_name=$FOLDER_NAME

if [[ "$folder_name" == '' ]]; then
echo folder_name=${{ github.event.repository.name }} >> $GITHUB_OUTPUT
else
echo folder_name=$FOLDER_NAME >> $GITHUB_OUTPUT
fi
# if [[ "$folder_name" == '' ]]; then
# echo folder_name=${{ github.event.repository.name }} >> $GITHUB_OUTPUT
# else
# echo folder_name=$FOLDER_NAME >> $GITHUB_OUTPUT
# fi

echo "repository_name=${{ github.event.repository.name }}" >> $GITHUB_OUTPUT
echo "release_name=${{ github.event.repository.name }}-pr-$EVENT_NUMBER-storybook" >> $GITHUB_OUTPUT
echo "pr_number=${{ inputs.pr-number }}" >> $GITHUB_OUTPUT
- name: Build and Push Storybook Image
uses: toptal/davinci-github-actions/[email protected]
if: ${{ inputs.use-prebuilt-image == 'false' }}
with:
sha: ${{ inputs.sha }}
image-name: ${{ steps.repo.outputs.repository_name }}-storybook-release
build-args: |
DIST_FOLDER=${{ inputs.dist-folder }}
NGINX_CONFIG=./davinci/packages/davinci/docker/nginx-vhost.conf
ENV_RUNTIME_ENTRYPOINT=./davinci/packages/ci/src/configs/docker/env-runtime.entrypoint.sh
VERSION=${{ inputs.sha }}
docker-file: ./davinci/packages/ci/src/configs/docker/Dockerfile.gha-deploy
davinci-branch: ${{ inputs.davinci-branch }}
# echo "repository_name=${{ github.event.repository.name }}" >> $GITHUB_OUTPUT
# echo "release_name=${{ github.event.repository.name }}-pr-$EVENT_NUMBER-storybook" >> $GITHUB_OUTPUT
# echo "pr_number=${{ inputs.pr-number }}" >> $GITHUB_OUTPUT

# - name: Build and Push Storybook Image
# uses: toptal/davinci-github-actions/[email protected]
# if: ${{ inputs.use-prebuilt-image == 'false' }}
# with:
# sha: ${{ inputs.sha }}
# image-name: ${{ steps.repo.outputs.repository_name }}-storybook-release
# build-args: |
# DIST_FOLDER=${{ inputs.dist-folder }}
# NGINX_CONFIG=./davinci/packages/davinci/docker/nginx-vhost.conf
# ENV_RUNTIME_ENTRYPOINT=./davinci/packages/ci/src/configs/docker/env-runtime.entrypoint.sh
# VERSION=${{ inputs.sha }}
# docker-file: ./davinci/packages/ci/src/configs/docker/Dockerfile.gha-deploy
# davinci-branch: ${{ inputs.davinci-branch }}

- name: Trigger Deploy to Staging
if: ${{ inputs.environment == 'staging' }}
uses: toptal/jenkins-job[email protected]
uses: toptal/actions/trigger-jenkins-job@main
env:
JENKINS_FOLDER_NAME: ${{ steps.repo.outputs.folder_name }}
REPOSITORY_NAME: ${{ steps.repo.outputs.repository_name }}
with:
jenkins_url: https://jenkins.toptal.net
jenkins_user: toptal-devbot
jenkins_token: ${{ env.JENKINS_DEPLOY_TOKEN }}
job_name: ${{ env.JENKINS_FOLDER_NAME }}/job/${{ env.REPOSITORY_NAME }}-storybook-staging-deployment
job_params: |
{
"TAG": "${{ inputs.sha }}"
}
jenkins_url: ${{ inputs.jenkins_url }}
jenkins_user: ${{ inputs.jenkins_user }} ##toptal-devbot
jenkins_token: ${{ inputs.jenkins_token }} ##${{ env.JENKINS_DEPLOY_TOKEN }}
jenkins_client_id: ${{ inputs.jenkins_client_id }}
jenkins_sa_credentials: ${{ inputs.jenkins_sa_credentials }}
# job_name: ${{ env.JENKINS_FOLDER_NAME }}/job/${{ env.REPOSITORY_NAME }}-storybook-staging-deployment
# job_params: |
# {
# "TAG": "${{ inputs.sha }}"
# }
job_name: job-test-iap
job_timeout: 1200

- uses: toptal/davinci-github-actions/[email protected]
if: ${{ inputs.environment == 'temploy' }}
id: env-variables
with:
github-token: ${{ env.GITHUB_TOKEN }}
filename: ${{ inputs.env-file }}
# - uses: toptal/davinci-github-actions/[email protected]
# if: ${{ inputs.environment == 'temploy' }}
# id: env-variables
# with:
# github-token: ${{ env.GITHUB_TOKEN }}
# filename: ${{ inputs.env-file }}

- name: Trigger Deploy to Temploy
if: ${{ inputs.environment == 'temploy' }}
uses: toptal/jenkins-job[email protected]
uses: toptal/actions/trigger-jenkins-job@main
env:
JENKINS_FOLDER_NAME: ${{ steps.repo.outputs.folder_name }}
REPOSITORY_NAME: ${{ steps.repo.outputs.repository_name }}
RELEASE: ${{ steps.repo.outputs.release_name }}
with:
jenkins_url: https://jenkins-build.toptal.net/
jenkins_url: ${{ inputs.jenkins_build_url }}
jenkins_user: toptal-jenkins
jenkins_token: ${{ env.JENKINS_DEPLOY_TOKEN }}
job_name: ${{ env.JENKINS_FOLDER_NAME }}/job/${{ env.REPOSITORY_NAME }}-storybook-temploy-helm-run
job_params: |
{
"REPOSITORY_NAME": "${{ env.REPOSITORY_NAME }}-storybook",
"RELEASE": "${{ env.RELEASE }}",
"TAG": "${{ inputs.sha }}",
"ENV": "${{ steps.env-variables.outputs.variables || 'ENV=null' }}"
}
jenkins_token: ${{ inputs.jenkins_build_token }} ###${{ env.JENKINS_DEPLOY_TOKEN }}
jenkins_client_id: ${{ inputs.jenkins_build_client_id }}
jenkins_sa_credentials: ${{ inputs.jenkins_sa_credentials }}
# job_name: ${{ env.JENKINS_FOLDER_NAME }}/job/${{ env.REPOSITORY_NAME }}-storybook-temploy-helm-run
# job_params: |
# {
# "REPOSITORY_NAME": "${{ env.REPOSITORY_NAME }}-storybook",
# "RELEASE": "${{ env.RELEASE }}",
# "TAG": "${{ inputs.sha }}",
# "ENV": "${{ steps.env-variables.outputs.variables || 'ENV=null' }}"
# }
job_name: job-test-iap
job_timeout: 1200

- name: Post Temploy Link
if: ${{ inputs.environment == 'temploy' }}
uses: actions/[email protected]
env:
RELEASE: ${{ steps.repo.outputs.release_name }}
PR_NUMBER: ${{ steps.repo.outputs.pr_number }}
with:
github-token: ${{ env.GITHUB_TOKEN }}
script: |
const trimSuffix = (name) => name.endsWith('-') ? name.slice(0, -1) : name
const { issue: { number: issue_number }, repo: { owner, repo } } = context
const name = trimSuffix(['${{ env.RELEASE }}', '${{ steps.repo.outputs.repository_name }}-storybook'].join('-').substring(0, 45))
const body = `Storybook temploy is available at https://${name}.toptal.rocks :tada:`
const number = issue_number || ${{ env.PR_NUMBER }}
github.rest.issues.createComment({ issue_number: number, owner, repo, body })
# - name: Post Temploy Link
# if: ${{ inputs.environment == 'temploy' }}
# uses: actions/[email protected]
# env:
# RELEASE: ${{ steps.repo.outputs.release_name }}
# PR_NUMBER: ${{ steps.repo.outputs.pr_number }}
# with:
# github-token: ${{ env.GITHUB_TOKEN }}
# script: |
# const trimSuffix = (name) => name.endsWith('-') ? name.slice(0, -1) : name
# const { issue: { number: issue_number }, repo: { owner, repo } } = context
# const name = trimSuffix(['${{ env.RELEASE }}', '${{ steps.repo.outputs.repository_name }}-storybook'].join('-').substring(0, 45))
# const body = `Storybook temploy is available at https://${name}.toptal.rocks :tada:`
# const number = issue_number || ${{ env.PR_NUMBER }}
# github.rest.issues.createComment({ issue_number: number, owner, repo, body })

0 comments on commit 8063a09

Please sign in to comment.