Skip to content

update

update #13

# This workflow will:
# 1. Create list of experiments
# - Read all feature flags from App Configuration file, or
# - Manually specify a single feature flag.
# 2. Analyze each experiment and save the results summary to a Markdown file.
# 3. Commit the analysis results to a dedicated branch in the GitHub repository.
#
# Prerequisites:
# - Copy to a new GitHub Actions workflow file in the .github/workflows directory.
# - Update the environment variables for your setup.
name: Analyze Experiments
# Update for your setup
env:
ANALYSIS_BRANCH: analysis-results
APP_CONFIGURATION_FILE: .config/feature-flags.json
METRIC_TAGS_ORDER: "Important, Usage, Cost, Performance, Errors, Feedback"
on:
push:
# trigger manually (via GitHub Actions UI)
workflow_dispatch:
inputs:
app-configuration-feature-flag:
description: "The App Configuration feature flag. By default, analyze all running experiments."
required: false
type: string
jobs:
list-experiments:
name: List experiments
runs-on: ubuntu-latest
outputs:
feature-flags: ${{ steps.write.outputs.feature-flags }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Read running experiments from config file
if: github.event_name == 'schedule' || github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.app-configuration-feature-flag == '')
run: echo "FEATURE_FLAGS=$(jq -c -n '[inputs.feature_management.feature_flags[] | select(.enabled and .allocation.percentile) | .id]' ${{ env.APP_CONFIGURATION_FILE }})" >> $GITHUB_ENV
- name: Propagate specified feature flag
if: github.event_name == 'workflow_dispatch' && github.event.inputs.app-configuration-feature-flag != ''
run: echo "FEATURE_FLAGS=[\"${{ github.event.inputs.app-configuration-feature-flag }}\"]" >> $GITHUB_ENV
- name: Export list
id: write
run: echo "feature-flags=$FEATURE_FLAGS" >> "$GITHUB_OUTPUT"
analysis:
name: Analysis of ${{ matrix.feature-flag }}
runs-on: ubuntu-latest
if: ${{ vars.AZURE_CLIENT_ID != '' }}
needs: list-experiments
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
feature-flag: ${{ fromJson(needs.list-experiments.outputs.feature-flags) }}
steps:
- name: Azure login using Federated Credentials
uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Summarize analysis results
id: results
uses: azure/online-experimentation-analysis@v1-beta
with:
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
resource-group: ${{ vars.LOG_ANALYTICS_WORKSPACE_RESOURCE_GROUP }}
log-analytics-workspace: ${{ vars.LOG_ANALYTICS_WORKSPACE_NAME }}
app-configuration-feature-flag: ${{ matrix.feature-flag }}
metric-tags-order: ${{ env.METRIC_TAGS_ORDER }}
- name: Save results to file
run: echo "$CONTENT" >> ${{ matrix.feature-flag }}.md
env:
CONTENT: ${{ steps.results.outputs.summary-md }}
- name: Upload results to GitHub Artifacts
uses: actions/upload-artifact@v4
with:
name: analysis-${{ matrix.feature-flag }}
path: ${{ matrix.feature-flag }}.md
commit:
name: Commit analysis results
runs-on: ubuntu-latest
needs: analysis
permissions:
contents: write
steps:
- name: Check ANALYSIS_BRANCH is set
if: env.ANALYSIS_BRANCH == ''
run: |
echo "::error ::You must set env.ANALYSIS_BRANCH in ${{ github.workflow }} GitHub Actions workflow"
exit 1
- uses: actions/checkout@v4
- name: Checkout analysis branch
run: |
set +e
git ls-remote --exit-code --heads origin refs/heads/"$ANALYSIS_BRANCH"
if [ "$?" == "2" ]; then
git checkout --orphan "$ANALYSIS_BRANCH"
git reset --hard
else
git fetch origin "$ANALYSIS_BRANCH"
git checkout "$ANALYSIS_BRANCH"
fi
- name: Download results from GitHub Artifacts
uses: actions/download-artifact@v4
with:
pattern: analysis-*
merge-multiple: true
- name: Write README.md
run: |
echo "# Experiment Analysis Results" > README.md
echo "" >> README.md
echo "This branch contains the latest analysis results of feature flag experiments." >> README.md
# recommendation: read the limitations of this 3rd party GitHub Action
- uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: ${{ env.ANALYSIS_BRANCH }}
create_branch: true
commit_message: "chore: update experiment analysis results"