forked from ontoportal/ontoportal_web_ui
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: auto deploy on push issue #917
Draft
Bilelkihal
wants to merge
3
commits into
development
Choose a base branch
from
fix/remove-auto-deploy-on-push
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+31
−39
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,5 @@ | ||
# Workflow to deploy OntoPortal UI to stage/prod systems | ||
# | ||
# Required github secrets: | ||
# | ||
# CONFIG_REPO - github repo containing config and customizations for UI. Format 'author/private_config_repo' | ||
# it is used for getting capistrano deployment configuration for stages on the github actions runner and | ||
# PRIVATE_CONFIG_REPO env var is constructed from it which is used by capistrano on the UI hosts for pulling configs. | ||
# | ||
# GH_PAT - github Personal Access Token for accessing private config repo | ||
# | ||
# SSH_JUMPHOST - ssh jump/proxy host though which deployments have to though if UI nodes live on private network. | ||
# SSH_JUMPHOST_USER - username to use to connect to the ssh jump/proxy. | ||
# | ||
# DEPLOY_ENC_KEY - key for decrypting deploymnet ssh key residing in config/ | ||
# this SSH key is used for accessing jump host, UI nodes, and private github repo. | ||
|
||
name: Capistrano Deployment | ||
|
||
# Controls when the action will run. | ||
on: | ||
push: | ||
|
@@ -26,67 +11,74 @@ on: | |
inputs: | ||
BRANCH: | ||
description: "Branch/tag to deploy" | ||
options: | ||
- stage | ||
- test | ||
- master | ||
default: stage | ||
required: true | ||
environment: | ||
description: "target environment to deploy to" | ||
description: "Target environment to deploy to" | ||
type: choice | ||
options: | ||
- staging | ||
- agroportal | ||
- test | ||
default: stage | ||
default: staging | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
env: | ||
BUNDLE_WITHOUT: default #install gems required primarely for deployment in order to speed up workflow | ||
BUNDLE_WITHOUT: default # Install gems required primarily for deployment to speed up workflow | ||
PRIVATE_CONFIG_REPO: ${{ format('[email protected]:{0}.git', secrets.CONFIG_REPO) }} | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
- name: set branch/tag and environment to deploy from inputs | ||
- name: Set branch/tag and environment to deploy from inputs | ||
run: | | ||
# workflow_dispatch default input doesn't get set on push so we need to set defaults | ||
# via shell parameter expansion | ||
# https://dev.to/mrmike/github-action-handling-input-default-value-5f2g | ||
USER_INPUT_BRANCH=${{ inputs.branch }} | ||
echo "BRANCH=${USER_INPUT_BRANCH:github.head_ref:-master}" >> $GITHUB_ENV | ||
# Set default branch/tag for push events | ||
BRANCH=${{ github.head_ref || 'master' }} | ||
echo "BRANCH=$BRANCH" >> $GITHUB_ENV | ||
|
||
USER_INPUT_ENVIRONMENT=${{ inputs.environment }} | ||
echo "TARGET=${USER_INPUT_ENVIRONMENT:-staging}" >> $GITHUB_ENV | ||
# Set default environment for push events | ||
if [ "${{ github.event_name }}" = "push" ]; then | ||
TARGET="staging" # Default to staging for push | ||
else | ||
TARGET=${{ inputs.environment }} | ||
fi | ||
echo "TARGET=$TARGET" >> $GITHUB_ENV | ||
|
||
CONFIG_REPO=${{ secrets.CONFIG_REPO }} | ||
GH_PAT=${{ secrets.GH_PAT }} | ||
echo "PRIVATE_CONFIG_REPO=https://${GH_PAT}@github.com/${CONFIG_REPO}" >> $GITHUB_ENV | ||
|
||
echo "SSH_JUMPHOST=${{ secrets.SSH_JUMPHOST }}" >> $GITHUB_ENV | ||
echo "SSH_JUMPHOST_USER=${{ secrets.SSH_JUMPHOST_USER }}" >> $GITHUB_ENV | ||
|
||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 2.7.6 # Not needed with a .ruby-version file | ||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically | ||
- name: get-deployment-config | ||
bundler-cache: true # Runs 'bundle install' and caches installed gems automatically | ||
|
||
- name: Get deployment config | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: ${{ secrets.CONFIG_REPO }} # repository containing deployment settings | ||
repository: ${{ secrets.CONFIG_REPO }} # Repository containing deployment settings | ||
token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT | ||
path: deploy_config | ||
- name: copy-deployment-config | ||
run: cp -r deploy_config/ontoportal_web_ui/${{ inputs.environment }}/* . | ||
# add ssh hostkey so that capistrano doesn't complain | ||
|
||
- name: Copy deployment config | ||
run: cp -r deploy_config/ontoportal_web_ui/${{ env.TARGET }}/* . | ||
|
||
# Add SSH host key so that Capistrano doesn't complain | ||
- name: Add jumphost's hostkey to Known Hosts | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ secrets.SSH_JUMPHOST }}" | ||
ssh-keyscan -H ${{ secrets.SSH_JUMPHOST }} > ~/.ssh/known_hosts | ||
shell: bash | ||
|
||
- uses: miloserdow/capistrano-deploy@master | ||
with: | ||
target: ${{ env.TARGET }} # which environment to deploy | ||
deploy_key: ${{ secrets.DEPLOY_ENC_KEY }} # Name of the variable configured in Settings/Secrets of your github project | ||
target: ${{ env.TARGET }} # Which environment to deploy | ||
deploy_key: ${{ secrets.DEPLOY_ENC_KEY }} # Name of the variable configured in Settings/Secrets of your GitHub project |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't default push into stage, it need to check the current pushed branch and depending on it decide where to push