Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/teamcity-remove-label-on-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
name: Remove TeamCity Label on Commit

on:
pull_request:
types: [synchronize]

permissions:
contents: read
pull-requests: write

jobs:
apply-outdated-label:
runs-on: ubuntu-latest
env:
TEAMCITY_LABELS: teamcity-passed,teamcity-failed,teamcity-new-failure
OUTDATED_LABEL: teamcity-outdated
PASSED_LABEL: teamcity-passed
steps:
- name: Check for TeamCity labels and apply outdated label
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const teamcityLabels = process.env.TEAMCITY_LABELS.split(',');
const outdatedLabel = process.env.OUTDATED_LABEL;
const passedLabel = process.env.PASSED_LABEL;

const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number
});

const labelNames = labels.map(label => label.name);
const hasTeamCityLabel = teamcityLabels.some(label => labelNames.includes(label));
const hasOutdatedLabel = labelNames.includes(outdatedLabel);
const hasPassedLabel = labelNames.includes(passedLabel);

if (hasTeamCityLabel) {
const foundLabels = teamcityLabels.filter(label => labelNames.includes(label));
core.info(`Found TeamCity labels: ${foundLabels.join(', ')}`);

if (!hasOutdatedLabel) {
core.info(`Applying "${outdatedLabel}" label to PR #${context.payload.pull_request.number}`);

try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: [outdatedLabel]
});

core.info(`Successfully applied "${outdatedLabel}" label`);
} catch (error) {
core.error(`Failed to apply "${outdatedLabel}" label: ${error.message}`);
throw error;
}
} else {
core.info(`Label "${outdatedLabel}" already exists on PR #${context.payload.pull_request.number}`);
}

// Remove passed label if it exists
if (hasPassedLabel) {
core.info(`Removing "${passedLabel}" label from PR #${context.payload.pull_request.number}`);

try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
name: passedLabel
});

core.info(`Successfully removed "${passedLabel}" label`);
} catch (error) {
if (error.status === 404) {
core.warning(`Label "${passedLabel}" was not found on PR #${context.payload.pull_request.number}`);
} else {
core.error(`Failed to remove "${passedLabel}" label: ${error.message}`);
throw error;
}
}
}
} else {
core.info(`No TeamCity labels found on PR #${context.payload.pull_request.number}`);
}
6 changes: 6 additions & 0 deletions .teamcity/components/build_azure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class ClientConfiguration(var clientId: String,
val betaVersionEnvVar : String,
val labelSuccess : String,
val labelFailure : String,
val labelOutdated : String,
val labelNewFailure : String,
val applyTestingLabelsEnabled : Boolean,
)

class LocationConfiguration(var primary : String, var secondary : String, var tertiary : String, var rotate : Boolean)
Expand Down Expand Up @@ -59,4 +62,7 @@ fun ParametrizedWithType.ConfigureAzureSpecificTestParameters(environment: Strin
hiddenVariable("env.TRACKING_ID", "0", "Tracking id for the comments posted by the build")
hiddenVariable("env.LABEL_SUCCESS", config.labelSuccess, "Label applied when teamcity build passed")
hiddenVariable("env.LABEL_FAILURE", config.labelFailure, "Label applied when teamcity build failed")
hiddenVariable("env.LABEL_OUTDATED", config.labelOutdated, "Label applied when teamcity build is outdated")
hiddenVariable("env.LABEL_NEW_FAILURE", config.labelNewFailure, "Label applied when teamcity build has new failures")
hiddenVariable("env.APPLY_TESTING_LABELS_ENABLED", config.applyTestingLabelsEnabled.toString(), "Whether to apply testing labels to PRs")
}
4 changes: 0 additions & 4 deletions .teamcity/components/settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ var serviceTestConfigurationOverrides = mapOf(
// Currently, we have insufficient quota to actually run these, but there are a few nodes in West Europe, so we'll pin it there for now
"vmware" to testConfiguration(parallelism = 3, locationOverride = LocationConfiguration("westeurope", "westus2", "eastus2", false)),

// In general, Azure Voice Service is available in several different regions, but each subscription will only be allowlisted for specific regions(`westcentralus`, `westcentralus`, `westcentralus`).
// Only the regions (`westcentralus`) is specified since the devtest subscription does not support creating resource group for the other two regions.
"voiceservices" to testConfiguration(parallelism = 3, locationOverride = LocationConfiguration("westcentralus", "westcentralus", "westcentralus", false)),

// Offset start hour to avoid collision with new App Service, reduce frequency of testing days
"web" to testConfiguration(startHour = 3, daysOfWeek = "1,3,5", locationOverride = LocationConfiguration("westeurope", "francecentral", "eastus2", true)),

Expand Down
50 changes: 30 additions & 20 deletions .teamcity/scripts/post_github_comment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ BETA_VERSION_ENV_VAR="%env.BETA_VERSION_ENV_VAR%"
TEAMCITY_BUILD_BRANCH="%teamcity.build.branch%"
LABEL_SUCCESS="%env.LABEL_SUCCESS%"
LABEL_FAILURE="%env.LABEL_FAILURE%"

LABEL_OUTDATED="%env.LABEL_OUTDATED%"
LABEL_NEW_FAILURE="%env.LABEL_NEW_FAILURE%"
APPLY_TESTING_LABELS_ENABLED="%env.APPLY_TESTING_LABELS_ENABLED%"

if [ "$POST_GITHUB_COMMENT" != "true" ]; then
echo "GitHub commenting disabled — skipping."
Expand Down Expand Up @@ -63,11 +65,20 @@ remove_label() {
set_testing_label() {
local label="$1"
if [ "$label" = "$LABEL_SUCCESS" ]; then
remove_label "$LABEL_OUTDATED"
remove_label "$LABEL_FAILURE"
remove_label "$LABEL_NEW_FAILURE"
apply_label "$LABEL_SUCCESS"
elif [ "$label" = "$LABEL_FAILURE" ]; then
remove_label "$LABEL_OUTDATED"
remove_label "$LABEL_SUCCESS"
remove_label "$LABEL_NEW_FAILURE"
apply_label "$LABEL_FAILURE"
elif [ "$label" = "$LABEL_NEW_FAILURE" ]; then
remove_label "$LABEL_OUTDATED"
remove_label "$LABEL_SUCCESS"
remove_label "$LABEL_FAILURE"
apply_label "$LABEL_NEW_FAILURE"
fi
}

Expand Down Expand Up @@ -269,25 +280,24 @@ curl -s -X POST \
"https://api.github.com/repos/$GITHUB_REPO/issues/${PR_NUMBER}/comments" \
-d "{\"body\": $(jq -Rs . <<< "$COMMENT")}"

echo "Applying labels..."
if APPLY_TESTING_LABELS_ENABLED; then
echo "Applying labels..."

# If no failures, apply teamcity-passed label
if [ "$FAIL_COUNT" -eq 0 ]; then
echo "No test failures detected"
set_testing_label "$LABEL_SUCCESS"
exit 0
fi
# If no failures, apply teamcity-passed label
if [ "$FAIL_COUNT" -eq 0 ]; then
echo "No test failures detected"
set_testing_label "$LABEL_SUCCESS"
exit 0
fi

# If there are failures, determine label based on earlier analysis
if [ -z "$MAIN_TEST_RESULTS" ]; then
echo "Could not fetch main branch results - applying '$LABEL_FAILURE' label as precaution..."
set_testing_label "$LABEL_FAILURE"
elif [ -z "$NEW_FAILURES" ]; then
echo "All failed tests also exist in main branch"
set_testing_label "$LABEL_SUCCESS"
else
echo "Found new test failures not present in main branch"
set_testing_label "$LABEL_FAILURE"
fi
# If there are failures, determine label based on earlier analysis
if [ -z "$NEW_FAILURES" ]; then
echo "All failed tests also exist in main branch"
set_testing_label "$LABEL_FAILURE"
else
echo "Found new test failures not present in main branch"
set_testing_label "$LABEL_NEW_FAILURE"
fi

echo "Label application complete"
echo "Label application complete"
fi
8 changes: 7 additions & 1 deletion .teamcity/settings.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ var teamcityToken = DslContext.getParameter("teamcityToken", "")
var betaVersionEnvVar = DslContext.getParameter("betaVersionEnvVar", "env.ARM_FIVEPOINTZERO_BETA")
var labelSuccess = DslContext.getParameter("labelSuccess", "teamcity-passed")
var labelFailure = DslContext.getParameter("labelFailure", "teamcity-failed")
var labelOutdated = DslContext.getParameter("labelOutdated", "teamcity-outdated")
var labelNewFailure = DslContext.getParameter("labelNewFailure", "teamcity-new-failure")
var applyTestingLabelsEnabled = DslContext.getParameter("applyTestingLabelsEnabled", "true").equals("true", ignoreCase = true)


var clientConfig = ClientConfiguration(
Expand All @@ -47,7 +50,10 @@ var clientConfig = ClientConfiguration(
teamcityToken,
betaVersionEnvVar,
labelSuccess,
labelFailure
labelFailure,
labelOutdated,
labelNewFailure,
applyTestingLabelsEnabled
)

project(AzureRM(environment, clientConfig))
5 changes: 4 additions & 1 deletion .teamcity/tests/helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ fun TestConfiguration() : ClientConfiguration {
"teamcityToken",
"env.ARM_FIVEPOINTZERO_BETA",
"teamcity-passed",
"teamcity-failed"
"teamcity-failed",
"teamcity-outdated",
"teamcity-new-failure",
false
)
}
Loading