Skip to content

Commit

Permalink
chore: support simpleauth cd on GitHub action (#1954)
Browse files Browse the repository at this point in the history
* chore: support simpleauth cd on github action

* chore: update

* chore: update

* chore: chrome dirver update

* chore: restore simpleauth setting config

* chore: update

* chore: udpate
  • Loading branch information
wenytang-ms authored Aug 25, 2021
1 parent f324d40 commit 8f74bb7
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 31 deletions.
18 changes: 18 additions & 0 deletions .github/scripts/pkg-postversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
if [[ $1 == 'templates' ]]; then
if [[ $SkipSyncup == *"template"* ]]; then
echo "skip sync up templates version with sdk version"
elif [[ -z "$(git tag --points-at HEAD | grep templates)" && ! -z "$(git diff HEAD^ -- ../../templates/package.json|grep version)" ]]
then
echo "need to tag on templates cause templates has no tags but bump up version"
git tag "templates@$(node -p "require('../../templates/package.json').version")"
fi
elif [[ $1 == 'fx-core' ]]; then
if [[ $SkipSyncup == *"fx-core"* ]]; then
echo "skip sync up fx-core version with simpleauth version"
elif [[ -z "$(git tag --points-at HEAD | grep @microsoft/teamsfx-core)" && ! -z "$(git diff HEAD^ -- ../fx-core/package.json|grep version)" ]]
then
echo "need to tag on fx-core cause fx-core has no tags but bump up version"
git tag "@microsoft/teamsfx-core@$(node -p "require('../fx-core/package.json').version")"
fi
fi
22 changes: 22 additions & 0 deletions .github/scripts/pkg-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
if [ $1 == 'templates' ]; then
if [[ $SkipSyncup == *"template"* ]]; then
echo "skip sync up templates version with sdk version"
elif [[ -z "$(git diff -- ../../templates)" ]]; then
echo "need bump up templates version since templates don not bump up by self"
node ../../.github/scripts/sdk-sync-up-version.js yes;
else
echo "no need to bump up templates version"
node ../../.github/scripts/sdk-sync-up-version.js
fi
git add ../../templates
elif [ $1 == 'fx-core' ]; then
if [[ -z "$(git diff -- ../fx-core)" ]]; then
echo "need bump up fx-core version since fx-core don not bump up by self"
node ../../.github/scripts/update-simpleauth-ver.js yes;
else
echo "no need to bump up templates version"
node ../../.github/scripts/update-simpleauth-ver.js
fi
git add ../fx-core
fi
6 changes: 0 additions & 6 deletions .github/scripts/sdk-postversion.sh

This file was deleted.

9 changes: 0 additions & 9 deletions .github/scripts/sdk-version.sh

This file was deleted.

26 changes: 26 additions & 0 deletions .github/scripts/simpleauth-azdo-pipelines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
countNum=1
restUrl="https://dev.azure.com/mseng/VSIoT/_apis/build/latest/$2?api-version=6.0-preview.1"
rsp=$(curl -u :$1 $restUrl | jq -r '.value| .[0]')
status=$(echo $rsp | jq -r '.state')
buildId=$(echo $rsp | jq -r '.id')
echo "===== build id is: " $buildId
echo "===== build pipeline status: " $status
while [[ $countNum -le 50 && "$status" != "completed" ]]
do
sleep 1m
rsp=$(curl -u :$1 $restUrl | jq -r '.value| .[0]')
status=$(echo $rsp | jq -r '.state')
echo "loop status" $status
countNum=$(( $countNum + 1 ))
done
if [[ "$status" != "completed" ]]
then
exit 1
fi

restUrl="https://dev.azure.com/mseng/VSIoT/_apis/build/builds/$buildId/artifacts?api-version=6.0"
asset_rsp=$(curl -u :$1 $restUrl)
echo "====== asset url response:" $asset_rsp
asset_id=$(echo $asset_rsp | jq '.value |.[] | .resource' |jq '.data' | tr -d -c 0-9)
echo "====== asset id is: " $asset_id
75 changes: 75 additions & 0 deletions .github/scripts/update-simpleauth-ver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const fs = require("fs");
const path = require("path")
const simpleauth = path.join(__dirname, "../../packages/simpleauth")
const xml2js = require(path.join(simpleauth, "node_modules/xml2js"))
const csprojFile = path.join(simpleauth, "src/TeamsFxSimpleAuth/Microsoft.TeamsFx.SimpleAuth.csproj");
const simpleauthVer = require(path.join(simpleauth, "package.json")).version
console.log("===== simple auth version: ", simpleauthVer)
// update .csproj file
fs.readFile(csprojFile, "utf-8", (err, data) => {
if (err) {
throw err;
}

// convert XML data to JSON object
xml2js.parseString(data, (err, result) => {
if (err) {
throw err;
}

// replace `version` with new version
for(let prop of result['Project'].PropertyGroup) {
if(prop.Version) {
prop.Version[0] = simpleauthVer;
break;
}
}
// convert SJON objec to XML
const builder = new xml2js.Builder({trim: true, headless: true});
const xml = builder.buildObject(result);

// write updated XML string to a file
fs.writeFile(csprojFile, xml, (err) => {
if (err) {
throw err;
}
console.log(`Updated XML is written to a new file.`);
});

});
});

const synup = process.env.SkipSyncup
if(synup && synup.includes("fx-core")) {
return;
}

// update fx-core tempaltes version.txt file
const fxCorePath = path.join(__dirname, "../../packages/fx-core");
const simpleauthVerTxt = path.join(fxCorePath, "./templates/plugins/resource/simpleauth/version.txt")
fs.writeFileSync(simpleauthVerTxt, simpleauthVer, "utf8")

// only rc and stable release bump up version on main branch, rarely run.
let needBumpUp = process.argv[2] === "yes" ? true : false;
if (needBumpUp) {
let file = path.join(fxCorePath, "package.json");
let pkg_ = fse.readJsonSync(file);
let ver = pkg_.version;
if (semver.prerelease(simpleauthVer)) {
ver = semver.inc(ver, "prerelease", "rc");
} else {
ver = semver.inc(ver, "patch");
}

pkg_.version = ver;
fse.writeFileSync(file, JSON.stringify(pkg_, null, 4));

file = path.join(fxCorePath, "package-lock.json");
if (file) {
pkg_ = fse.readJsonSync(file);
pkg_.version = ver;
fse.writeFileSync(file, JSON.stringify(pkg_, null, 4))
}

console.log("bump up fx-core version as ", ver);
}
83 changes: 71 additions & 12 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
description: "release RC version just with lerna publish, skip run lerna version(yes or no)"
required: false
default: "no"
skip-sync-version-pkg:
description: "skip sync up target pkg version. input templates to skip sync up version with sdk; fx-core to skip sync up with simpleauth"
required: false
default: ""
schedule:
- cron: "0 8 * * *"

Expand Down Expand Up @@ -55,20 +59,15 @@ jobs:
with:
node-version: 14

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x

- name: Setup npm registry
run: |
echo "${{ secrets.NPMRC }}" > ~/.npmrc
- name: Download Simple Auth bits
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 10
retry_on: error
shell: pwsh
command: |
./.github/scripts/downloadSimpleAuth.ps1
- name: Setup project
run: |
npm run setup
Expand All @@ -87,24 +86,32 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.preid == 'rc' && github.ref == 'refs/heads/main' && github.event.inputs.skip-version-rc == 'no'}}
run: |
npx lerna version --conventional-commits --conventional-prerelease --preid=rc --no-changelog --ignore-scripts --yes
env:
SkipSyncup: ${{ github.event.inputs.skip-sync-version-pkg }}

- name: version rc npm packages to npmjs.org on hotfix
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.preid == 'rc' && startsWith(github.ref, 'refs/heads/hotfix/') && github.event.inputs.skip-version-rc == 'no'}}
run: |
npx lerna version --conventional-commits --conventional-prerelease --preid=rc-hotfix --no-changelog --allow-branch ${GITHUB_REF#refs/*/} --ignore-scripts --yes
env:
SkipSyncup: ${{ github.event.inputs.skip-sync-version-pkg }}

- name: version stable npm packages to npmjs.org
if: ${{ github.event_name == 'workflow_dispatch' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/hotfix/')) && github.event.inputs.preid == 'stable' }}
run: |
npx lerna version --conventional-commits --conventional-graduate --no-changelog --allow-branch ${GITHUB_REF#refs/*/} --yes
env:
SkipSyncup: ${{ github.event.inputs.skip-sync-version-pkg }}

- name: version change
id: version-change
run: |
echo "::set-output name=CHANGED::$(git tag --points-at HEAD | xargs)"
echo "::set-output name=TEMPLATE_VERSION::$(git tag --points-at HEAD | grep templates)"
echo "::set-output name=EXTENSION_VERSION_NUM::$(git tag --points-at HEAD | grep ms-teams-vscode-extension@ | cut -d '@' -f2)"
echo "::set-output name=EXTENSION_VERSION::$(git tag --points-at HEAD | grep ms-teams-vscode-extension@)"
echo "::set-output name=SIMPLEAUTH_VERSION::$(git tag --points-at HEAD | grep simpleauth)"
echo "::set-output name=SIMPLEAUTH_VERSION_NUM::$(git tag --points-at HEAD| grep simpleauth| cut -d '@' -f2)"
if git tag --points-at HEAD | grep templates | grep rc;
then
git push -d origin $(git tag --points-at HEAD | grep templates | grep rc)
Expand Down Expand Up @@ -179,6 +186,58 @@ jobs:
- name: cleanup templates
run: rm -rf ./*.zip && git clean -df

- name: trigger simpleauth azure build pipeline for stable release
if: ${{ contains(steps.version-change.outputs.CHANGED, 'simpleauth') && github.event_name == 'workflow_dispatch' && github.event.inputs.preid == 'stable' }}
uses: Azure/pipelines@v1
with:
azure-devops-project-url: 'https://dev.azure.com/mseng/VSIoT'
azure-pipeline-name: 'Build Simple Auth Release Artifacts'
azure-devops-token: '${{ secrets.ADO_PAT }}'

- name: check build status and download assets for stable release
if: ${{ contains(steps.version-change.outputs.CHANGED, 'simpleauth') && github.event_name == 'workflow_dispatch' && github.event.inputs.preid == 'stable' }}
run: |
output=$(./.github/scripts/simpleauth-azdo-pipelines.sh ${{ secrets.ADO_PAT }} 11303 >&1)
echo $output
asset_id=$(echo $output | rev |cut -d ' ' -f 1 | rev)
curl "https://dev.azure.com/mseng/_apis/resources/Containers/$asset_id/drop?itemPath=drop/Microsoft.TeamsFx.SimpleAuth_${{ steps.version-change.outputs.SIMPLEAUTH_VERSION_NUM }}.zip" -L -O -u :${{ secrets.ADO_PAT }}
if [ ! -f Microsoft.TeamsFx.*.zip ]; then exit 1; fi
- name: build SimpleAuth on prerelease
if: ${{ contains(steps.version-change.outputs.CHANGED, 'simpleauth') && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' && github.event.inputs.preid != 'stable') }}
run: |
dotnet build --configuration Release
zip -r -j ../../Microsoft.TeamsFx.SimpleAuth_${{ steps.version-change.outputs.SIMPLEAUTH_VERSION_NUM }}.zip src/TeamsFxSimpleAuth/bin/Release/*
working-directory: ./packages/simpleauth

- name: download simpleauth to fx-core
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 10
retry_on: error
command: |
if [ -f Microsoft.TeamsFx.SimpleAuth_*.zip ]; then
cp Microsoft.TeamsFx.SimpleAuth_*.zip packages/fx-core/templates/plugins/resource/simpleauth/SimpleAuth.zip
else
./.github/scripts/downloadSimpleAuth.ps1
fi
- name: publish alpha simpleauth to github release page
if: ${{ contains(steps.version-change.outputs.CHANGED, 'simpleauth') && github.ref == 'refs/heads/dev' }}
uses: ncipollo/release-action@v1.7.3
with:
token: ${{ secrets.CD_PAT }}
tag: 'simpleauth-${{steps.version-change.outputs.SIMPLEAUTH_VERSION_NUM}}'
artifacts: Microsoft.TeamsFx.SimpleAuth_*.zip

- name: publish simpleauth to github release page
if: ${{ contains(steps.version-change.outputs.CHANGED, 'simpleauth') && github.ref == 'refs/heads/main'}}
uses: ncipollo/release-action@v1.7.3
with:
token: ${{ secrets.CD_PAT }}
tag: ${{ steps.version-change.outputs.SIMPLEAUTH_VERSION }}
artifacts: Microsoft.TeamsFx.SimpleAuth_*.zip

- name: publish alpha release to npm org
if: ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/dev' && github.event.inputs.preid == 'alpha')}}
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ test-results.*
# simple auth
SimpleAuth.zip
SimpleAuthUnzipOutput
Microsoft.TeamsFx.SimpleAuth_*.zip

# so you can npm install inside a template and not worry about committing
templates/*/*/package-lock.json
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"packages/cli",
"packages/vscode-extension",
"packages/failpoint-ts",
"packages/simpleauth",
"templates"
],
"command": {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"test:unit": "npm run build:test && npm run unit-test:node && npm run unit-test:browser",
"ui-test": "mocha --no-timeouts -r test/mocha.env.ts -r ts-node/register test/ui/**/*.spec.ts --exit",
"precommit": "lint-staged",
"version": "../../.github/scripts/sdk-version.sh",
"postversion": "../../.github/scripts/sdk-postversion.sh"
"version": "../../.github/scripts/pkg-version.sh templates",
"postversion": "../../.github/scripts/pkg-postversion.sh templates"
},
"files": [
"dist/",
Expand Down
Loading

0 comments on commit 8f74bb7

Please sign in to comment.