Skip to content

Commit

Permalink
Merge pull request #121 from Scalr/feature/SCALRCORE-26666
Browse files Browse the repository at this point in the history
SCALRCORE-26666: Move all branch and image detection logic from shell to cli te up command
  • Loading branch information
AKramarenko committed Jun 30, 2023
2 parents a8bd853 + 39d4032 commit 0f3cffe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
55 changes: 33 additions & 22 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,44 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: "1.18"
- name: Set API_BRANCH
run: echo "API_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Check if same branch exists in fatmouse repository
id: check-branch
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_PAT }}
script: |
const owner = "Scalr";
const repo = "fatmouse";
const targetBranch = "${{ env.API_BRANCH }}";
const default_branch = "master";
try {
const { data: branch } = await github.request('GET /repos/{owner}/{repo}/branches/{branch}', {
owner: owner,
repo: repo,
branch: targetBranch
});

console.log(`Branch found in the ${repo} repository: ${branch.name}`);
core.setOutput('branch', branch.name);
} catch (error) {
if (error.status === 404) {
console.log(`Branch not found in ${repo} repository.`);
core.setOutput('branch', default_branch);
} else {
console.error('Unexpected error:', error);
core.setFailed('Unexpected error');
}
}
- name: Clone fatmouse repo
uses: actions/checkout@v3
with:
repository: Scalr/fatmouse
path: fatmouse
ref: ${{ steps.check-branch.outputs.branch }}
token: ${{ secrets.GH_PAT }}
- name: Set API_BRANCH
if: ${{ contains(github.event.head_commit.message, '[API_BRANCH]') }}
run: echo "API_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Set DB_BRANCH
if: ${{ contains(github.event.head_commit.message, '[DB_BRANCH]') }}
run: echo "DB_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
Expand Down Expand Up @@ -79,24 +108,6 @@ jobs:
id: create
shell: bash
run: |
if [ -z ${{ env.API_BRANCH }} ]; then
FATMOUSE_BRANCH=""
else
FATMOUSE_BRANCH="--fatmouse-branch ${{ env.API_BRANCH }}"
fi
if [ -z ${{ env.DB_BRANCH }} ]; then
SCALR_BRANCH=""
else
SCALR_BRANCH="--scalr-branch ${{ env.DB_BRANCH }}"
fi
if [ "${{ env.API_BRANCH }}" = "staging" ]; then
IMAGE="--scalr-server-image-tag staging"
else
IMAGE=""
fi
docker run --rm \
-e GITHUB_WORKSPACE=true \
-e GITHUB_OUTPUT=/fatmouse/output \
Expand All @@ -105,7 +116,7 @@ jobs:
-v $GITHUB_OUTPUT:/fatmouse/output \
-v ~/.scalr-labs:/etc/scalr-labs \
fatmouse/python-builder:master python -u clickfile.py te up \
${FATMOUSE_BRANCH} ${SCALR_BRANCH} ${IMAGE} \
--branch ${{ env.API_BRANCH }} \
--run-url ${{ steps.get-job-id.outputs.html_url }} \
--skip-ui-build \
${{ env.RUN_TAG }}
Expand Down
19 changes: 2 additions & 17 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
with:
repository: Scalr/fatmouse
path: fatmouse
ref: ${{ inputs.pr_branch }}
token: ${{ secrets.GH_PAT }}
- name: Set DB_BRANCH
if: ${{ contains(github.event.head_commit.message, '[DB_BRANCH]') }}
Expand Down Expand Up @@ -98,22 +99,6 @@ jobs:
id: create
shell: bash
run: |
FATMOUSE_BRANCH="--fatmouse-branch ${{ inputs.pr_branch }}"
SCALR_BRANCH="--scalr-branch ${{ inputs.pr_branch }}"
TEV2_BRANCH=${{ inputs.pr_branch }}
NORMALIZED_BRANCH=$(echo $TEV2_BRANCH | tr / - | tr '[:upper:]' '[:lower:]')
if docker manifest inspect eu.gcr.io/development-156220/fatmouse/scalr-server-te:${NORMALIZED_BRANCH} ; then
IMAGE="--scalr-server-image-tag ${NORMALIZED_BRANCH}"
else
if [[ "${{ inputs.base_branch }}" == release/* ]]; then
NORMALIZED_IMAGE=$(echo "${{ inputs.base_branch }}" | tr / - | tr '[:upper:]' '[:lower:]')
IMAGE="--scalr-server-image-tag ${NORMALIZED_IMAGE}"
else
IMAGE=""
fi
fi
docker run --rm \
-e GITHUB_WORKSPACE=true \
-e GITHUB_OUTPUT=/fatmouse/output \
Expand All @@ -122,7 +107,7 @@ jobs:
-v $GITHUB_OUTPUT:/fatmouse/output \
-v ~/.scalr-labs:/etc/scalr-labs \
fatmouse/python-builder:master python -u clickfile.py te up \
${FATMOUSE_BRANCH} ${SCALR_BRANCH} ${IMAGE} \
--branch ${{ inputs.pr_branch }} \
--run-url ${{ steps.get-job-id.outputs.html_url }} \
--skip-ui-build \
${{ env.RUN_TAG }}
Expand Down

0 comments on commit 0f3cffe

Please sign in to comment.