ci(sonar): use latest sonarcloud orb (IN-976) #358
Workflow file for this run
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: PR-label -> clean-up dev env | |
on: | |
pull_request: | |
types: [closed, unlabeled] | |
concurrency: | |
group: delete-env-${{ github.ref }} | |
jobs: | |
preview: | |
name: Clean up dev environment | |
runs-on: ubuntu-latest | |
continue-on-error: true # Ignore errors | |
if: ${{ github.actor != 'dependabot[bot]' }} | |
steps: | |
- name: Check PR env labels | |
uses: voiceflow/pr-label-match@master | |
with: | |
regex: env- | |
id: envNameLabel | |
- name: Find Comment Created | |
uses: peter-evans/find-comment@v1 | |
id: commentCreated | |
with: | |
token: ${{ secrets.GH_SA_TOKEN }} | |
comment-author: vf-service-account | |
issue-number: ${{ github.event.number }} | |
body-includes: https://creator- | |
direction: last | |
- name: Find Comment Destroyed | |
uses: peter-evans/find-comment@v1 | |
id: commentDestroyed | |
with: | |
token: ${{ secrets.GH_SA_TOKEN }} | |
comment-author: vf-service-account | |
issue-number: ${{ github.event.number }} | |
body-includes: destroyed! | |
direction: last | |
- name: Remove environment label | |
uses: buildsville/add-remove-label@v1 | |
if: (github.event.action == 'closed' && steps.envNameLabel.outputs.label != '') | |
with: | |
token: ${{ secrets.GH_SA_TOKEN }} | |
label: ${{ steps.envNameLabel.outputs.label}} | |
type: remove | |
- name: Install vfcli | |
if: (github.event.action == 'closed' && steps.envNameLabel.outputs.label != '') || (github.event.action == 'unlabeled' && steps.envNameLabel.outputs.label == '' && steps.commentCreated.outputs.comment-body != '') | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_SA_TOKEN }} | |
run: | | |
API_URL="https://$GITHUB_TOKEN:@api.github.com/repos/voiceflow/vfcli" | |
ASSET_ID=$(curl $API_URL/releases/latest | jq -r '.assets[3].id') | |
curl -J -L -H "Accept: application/octet-stream" "$API_URL/releases/assets/$ASSET_ID" --output vfcli.tar.gz | |
tar -xf vfcli.tar.gz | |
- name: Delete the dev env if PR closed not creating and the label exists | |
if: (github.event.action == 'closed' && steps.envNameLabel.outputs.label != '') || (github.event.action == 'unlabeled' && steps.envNameLabel.outputs.label == '' && steps.commentCreated.outputs.comment-body != '') | |
id: deleteEnv | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: 'us-east-1' | |
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GH_SA_TOKEN }} | |
run: | | |
echo "Initializating vfcli..." | |
./vfcli init --interactive false | |
# Remove environment | |
LABEL=${{ steps.envNameLabel.outputs.label }} | |
if [[ $LABEL != "" ]] | |
then | |
ENV_NAME=$LABEL | |
ENV_NAME=$(sed 's|env-||g' <<< "$ENV_NAME") | |
else | |
ENV_NAME=$(sed 's|https://creator-||g' <<< "${{ steps.commentCreated.outputs.comment-body }}") | |
ENV_NAME=$(echo $ENV_NAME | cut -d. -f1) | |
LAST_COMMENT_DESTROYED="${{ steps.commentDestroyed.outputs.comment-body }}" | |
# if it is already destroyed, do now continue | |
if [[ $LAST_COMMENT_DESTROYED == *"$ENV_NAME"* ]] | |
then | |
echo "Environment $ENV_NAME already deleted" | |
exit 0 | |
fi | |
fi | |
./vfcli env delete -n ${ENV_NAME} --interactive false --no-telepresence | |
echo -e "::set-output name=deleted::true" | |
echo -e "::set-output name=envName::${ENV_NAME}" | |
- name: Comment PR | |
uses: thollander/actions-comment-pull-request@main | |
if: steps.deleteEnv.outputs.deleted == 'true' | |
with: | |
message: 'Dev environment ${{ steps.deleteEnv.outputs.envName}} destroyed!' | |
GITHUB_TOKEN: ${{ secrets.GH_SA_TOKEN }} | |
- name: Remove track if exists | |
if: steps.deleteEnv.outputs.deleted == 'true' | |
id: deleteTrack | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: 'us-east-1' | |
run: | | |
COMPONENT=$(echo "${GITHUB_REPOSITORY}" | sed 's:.*/::') | |
BRANCH="$(echo ${GITHUB_HEAD_REF#refs/heads/})" | |
TRACK="tracks/$COMPONENT/$BRANCH" | |
BUCKET="com.voiceflow.ci.assets" | |
echo $TRACK | |
set +e | |
aws s3 cp s3://$BUCKET/$TRACK /tmp/$TRACK | |
SEARCH_TRACK_RESULT=$? | |
set -e | |
# Store the result on a file in tmp folder to use in future steps | |
if [[ $SEARCH_TRACK_RESULT -eq 0 ]]; then | |
echo "Track $TRACK exists. Removing.." | |
aws s3 rm s3://$BUCKET/$TRACK | |
else | |
echo "Track $TRACK does not exist" | |
fi |