Forgot block #10388
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: test_release | |
on: | |
push: | |
branches: | |
- 'test_*' | |
workflow_dispatch: | |
jobs: | |
build-test-release: | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write | |
contents: write | |
deployments: write | |
packages: none | |
pull-requests: write | |
security-events: write | |
if: startsWith(github.ref, 'refs/heads/test_') | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 2 | |
ref: ${{ github.ref }} | |
- name: Prepare scenarios to be released. | |
run: | | |
sudo apt install zip | |
zip -r scenarios.zip scenarios | |
languages=("cs-CZ" "de-DE" "es-ES" "fr-FR" "hu-HU" "id-ID" "it-IT" "ja-JP" "ko-KR" "nl-NL" "pl-PL" "pt-BR" "pt-PT" "ru-RU" "sv-SE" "tr-TR" "zh-CN" "zh-TW") | |
for lang in "${languages[@]}"; do | |
# Set the source directory | |
src_dir="localized/$lang" | |
# Set the destination zip file | |
zip_file="${lang}-scenarios.zip" | |
# Change to the source directory and create the zip file | |
(cd "$src_dir" && zip -r "../../$zip_file" scenarios) | |
done | |
- name: Check for changes in 'Scenarios' folder | |
id: check_changes | |
run: | | |
CHANGED=$(git diff --name-only HEAD^ HEAD -- scenarios) | |
if [ -n "$CHANGED" ]; then | |
echo "Changes detected in Scenarios folder." | |
echo "scenarios_changed=true" >> $GITHUB_ENV | |
else | |
echo "No changes detected in Scenarios folder." | |
echo "scenarios_changed=false" >> $GITHUB_ENV | |
fi | |
- name: Get count of successful runs | |
id: get_count | |
run: | | |
# Replace `workflow_id` with your actual workflow file name or ID | |
# Replace `your_token` with a GitHub token with appropriate permissions | |
WORKFLOW_RUNS=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/test_release.yml/runs?per_page=1") | |
SUCCESS_COUNT=${{ github.run_id }} | |
echo "Total successful runs: $SUCCESS_COUNT" | |
echo "success_count=$SUCCESS_COUNT" >> $GITHUB_ENV | |
- name: Check if release exists | |
id: check_release | |
run: | | |
RELEASE_EXISTS=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/releases/tags/t1.0.${{ env.success_count }}" | jq -r '.id != null') | |
echo "release_exists=$RELEASE_EXISTS" >> $GITHUB_ENV | |
- name: Setup release | |
if: env.scenarios_changed == 'true' | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: t1.0.${{ env.success_count }} | |
release_name: t1.0.${{ env.success_count }} | |
draft: false | |
prerelease: true | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./scenarios.zip | |
asset_name: scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./cs-CZ-scenarios.zip | |
asset_name: cs-cz-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./de-DE-scenarios.zip | |
asset_name: de-de-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./es-ES-scenarios.zip | |
asset_name: es-es-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./fr-FR-scenarios.zip | |
asset_name: fr-fr-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./hu-HU-scenarios.zip | |
asset_name: hu-hu-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./id-ID-scenarios.zip | |
asset_name: id-id-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./it-IT-scenarios.zip | |
asset_name: it-it-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./ja-JP-scenarios.zip | |
asset_name: ja-jp-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./ko-KR-scenarios.zip | |
asset_name: ko-kr-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./nl-NL-scenarios.zip | |
asset_name: nl-nl-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./pl-PL-scenarios.zip | |
asset_name: pl-pl-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./pt-BR-scenarios.zip | |
asset_name: pt-br-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./pt-PT-scenarios.zip | |
asset_name: pt-pt-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./ru-RU-scenarios.zip | |
asset_name: ru-ru-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./sv-SE-scenarios.zip | |
asset_name: sv-se-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./tr-TR-scenarios.zip | |
asset_name: tr-tr-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./zh-CN-scenarios.zip | |
asset_name: zh-cn-scenarios.zip | |
asset_content_type: application/zip | |
- name: Upload Release Asset | |
if: env.scenarios_changed == 'true' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./zh-TW-scenarios.zip | |
asset_name: zh-tw-scenarios.zip | |
asset_content_type: application/zip | |
- name: Create Pull Request | |
if: env.scenarios_changed == 'true' | |
run: | | |
# Replace `branch_name` with the name of your branch | |
BRANCH_NAME=$(git branch --show-current) | |
PR_TITLE="Merge $BRANCH_NAME to main" | |
# Extract author information from the file | |
FILE_PATH=$(echo $BRANCH_NAME | sed 's/_/\//g') | |
# Check if the file exists | |
if [ -f "$FILE_PATH" ]; then | |
AUTHOR=$(grep -oP 'author: \K(.+)' $FILE_PATH || echo "") | |
MS_AUTHOR=$(grep -oP 'ms.author: \K(.+)' $FILE_PATH || echo "") | |
else | |
AUTHOR="" | |
MS_AUTHOR="" | |
fi | |
PR_BODY="This PR attempts to publish your Exec Doc. In order to do that, please test your Exec Doc associated with the branch $BRANCH_NAME in the URL below.\n\nExec Doc Test URL: https://ms.portal.azure.com/?Microsoft_Azure_CloudNative_clientoptimizations=false&feature.canmodifyextensions=true&feature.scenarioTester=true#view/Microsoft_Azure_CloudNative/TutorialsPage.ReactView/scenariosVersion/t1.0.${{ env.success_count }}\n\nAuthors: @$AUTHOR, @$MS_AUTHOR, @naman-msft" | |
PR_API_URL="https://api.github.com/repos/${{ github.repository }}/pulls" | |
PR_PAYLOAD="{\"title\":\"$PR_TITLE\",\"body\":\"$PR_BODY\",\"head\":\"$BRANCH_NAME\",\"base\":\"main\"}" | |
PR_RESPONSE=$(curl -X POST -H "Authorization: token ${{ secrets.PAT }}" -H "Content-Type: application/json" -d "$PR_PAYLOAD" "$PR_API_URL") | |
echo $PR_RESPONSE | |
PR_NUMBER=$(echo $PR_RESPONSE | jq '.number') | |
echo "Pull Request created: #$PR_NUMBER" | |
# Add org admin as a mandatory reviewer | |
REVIEWERS_API_URL="https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/requested_reviewers" | |
REVIEWERS_PAYLOAD="{\"reviewers\":[\"naman-msft\"]}" | |
REVIEWERS_RESPONSE=$(curl -X POST -H "Authorization: token ${{ secrets.PAT }}" -H "Content-Type: application/json" -d "$REVIEWERS_PAYLOAD" "$REVIEWERS_API_URL") | |
echo $REVIEWERS_RESPONSE | |