Skip to content

Commit

Permalink
Merge pull request #255 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 707e46c + b69d5f2 commit 6b4c8ac
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 61 deletions.
60 changes: 33 additions & 27 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,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
- id: auth
uses: google-github-actions/auth@v0
with:
Expand Down Expand Up @@ -91,29 +120,6 @@ jobs:
id: create
shell: bash
run: |
echo "::group::Analyze branches"
if [ -z "${{ env.API_BRANCH }}" ] || [ "${{ env.API_BRANCH }}" = "master" ]; then
FATMOUSE_BRANCH=""
SCALR_BRANCH=""
else
FATMOUSE_BRANCH="--fatmouse-branch ${{ env.API_BRANCH }}"
SCALR_BRANCH="--scalr-branch ${{ env.API_BRANCH }}"
fi
TEV2_BRANCH="${{ env.API_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 [[ "${{ github.base_ref }}" == release/* ]]; then
NORMALIZED_IMAGE=$(echo "${{ github.base_ref }}" | tr / - | tr '[:upper:]' '[:lower:]')
IMAGE="--scalr-server-image-tag ${NORMALIZED_IMAGE}"
else
IMAGE=""
fi
fi
echo "::endgroup::"
docker run --rm \
-e GITHUB_WORKSPACE=true \
-e GITHUB_OUTPUT=/fatmouse/output \
Expand All @@ -122,7 +128,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
24 changes: 1 addition & 23 deletions .github/workflows/upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,6 @@ jobs:
id: create
shell: bash
run: |
echo "::group::Analyze branches"
if [ -z "${{ env.API_BRANCH }}" ] || [ "${{ env.API_BRANCH }}" = "master" ]; then
FATMOUSE_BRANCH=""
SCALR_BRANCH=""
else
FATMOUSE_BRANCH="--fatmouse-branch ${{ env.API_BRANCH }}"
SCALR_BRANCH="--scalr-branch ${{ env.API_BRANCH }}"
fi
TEV2_BRANCH="${{ env.API_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 [[ "${{ env.UPSTREAM_BASE_REF }}" == release/* ]]; then
NORMALIZED_IMAGE=$(echo "${{ env.UPSTREAM_BASE_REF }}" | tr / - | tr '[:upper:]' '[:lower:]')
IMAGE="--scalr-server-image-tag ${NORMALIZED_IMAGE}"
else
IMAGE=""
fi
fi
echo "::endgroup::"
docker run --rm \
-e GITHUB_WORKSPACE=true \
-e GITHUB_OUTPUT=/fatmouse/output \
Expand All @@ -133,7 +111,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
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,4 @@ TESTARGS="-run TestAccScalrWorkspace_basic TestAccScalrWorkspace_update" make te

#### Acceptance tests

To run tests with the container from the current branch. You need to specify branch flags in the commit message.
Flags:
- `[API_BRANCH]` - whether to use current branch as API branch.

For example, commit message:
```
Commit title
Some description
[API_BRANCH]
```
The required parameters for creating a container will be determined automatically based on existing branches and pull requests in other repositories. No more need to add `[API_BRANCH]`

0 comments on commit 6b4c8ac

Please sign in to comment.