diff --git a/.github/workflows/resource.deployment.template.yml b/.github/workflows/resource.deployment.template.yml new file mode 100644 index 0000000000..95e1a3a7a8 --- /dev/null +++ b/.github/workflows/resource.deployment.template.yml @@ -0,0 +1,189 @@ +name: "Resources: Test Pipeline Template" + +on: + workflow_dispatch: + inputs: + removeDeployment: + description: 'Remove deployed module' + required: false + default: 'true' + versioningOption: + description: 'The mode to handle the version increments [major|minor|patch|custom]' + required: false + default: 'patch' + customVersion: + description: 'The version to enforce if [versionOption] is set to [custom]' + required: false + default: '0.0.1' + moduleName: + description: 'moduleName' + required: true + # default: '0.0.1' + modulePath: + description: 'modulePath' + required: true + # default: '0.0.1' + +env: + # moduleName: 'resourceGroups' + # modulePath: 'arm/Microsoft.Resources/resourceGroups' + ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} + ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} + ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} + ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} + ARM_MGMTGROUP_ID: ${{ secrets.ARM_MGMTGROUP_ID }} + +jobs: + ################## + # UNIT TESTS # + ################## + # Global tests + # ------------ + job_tests_module_global: + runs-on: ubuntu-20.04 + name: "Run global module tests" + steps: + - name: "Checkout" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: "Test module" + uses: ./.github/actions/templates/validateModuleGeneral + with: + modulePath: '${{ env.modulePath }}' + moduleName: '${{ env.moduleName}}' + + # Global API tests + # ---------------- + job_tests_module_global_api: + runs-on: ubuntu-20.04 + name: "Run global API module tests" + steps: + - name: "Checkout" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: "Test module" + uses: ./.github/actions/templates/validateModuleApis + with: + modulePath: '${{ env.modulePath }}' + moduleName: '${{ env.moduleName}}' + + # Validate deployment module tests + # -------------------------------- + job_tests_module_deploy_validate: + runs-on: ubuntu-20.04 + name: "Run deployment validation module tests" + strategy: + matrix: + parameterFilePaths: ['parameters.json'] + steps: + - name: "Checkout" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set environment variables + uses: deep-mm/set-variables@v1.0 + with: + # Name of variable file + variableFileName: 'variables.module' # Don't write .json here + - name: "Test module" + uses: ./.github/actions/templates/validateModuleDeploy + with: + templateFilePath: '${{ env.modulePath }}/deploy.json' + parameterFilePath: '${{ env.modulePath }}/parameters/${{ matrix.parameterFilePaths }}' + location: '${{ env.defaultLocation }}' + resourceGroupName: '${{ env.resourceGroupName }}' + subscriptionId: '${{ secrets.ARM_SUBSCRIPTION_ID }}' + managementGroupId: '${{ secrets.ARM_MGMTGROUP_ID }}' + + #################### + # DEPLOY TESTS # + #################### + job_deploy_module: + runs-on: ubuntu-20.04 + name: "Deploy module" + needs: + - job_tests_module_global + - job_tests_module_global_api + - job_tests_module_deploy_validate + strategy: + matrix: + parameterFilePaths: ['parameters.json'] + steps: + - name: "Checkout" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set environment variables + uses: deep-mm/set-variables@v1.0 + with: + # Name of variable file + variableFileName: 'variables.module' # Don't write .json here + - name: "Deploy module" + uses: ./.github/actions/templates/deployModule + with: + moduleName: '${{ env.moduleName }}' + templateFilePath: '${{ env.modulePath }}/deploy.json' + parameterFilePath: '${{ env.modulePath }}/parameters/${{ matrix.parameterFilePaths }}' + location: '${{ env.defaultLocation }}' + resourceGroupName: '${{ env.resourceGroupName }}' + subscriptionId: '${{ secrets.ARM_SUBSCRIPTION_ID }}' + managementGroupId: '${{ secrets.ARM_MGMTGROUP_ID }}' + removeDeployment: '${{ github.event.inputs.removeDeployment }}' + + ############### + # PUBLISH # + ############### + job_publish_module: + runs-on: ubuntu-20.04 + name: "Publish module" + needs: + - job_deploy_module + steps: + - name: "Checkout" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set environment variables + uses: deep-mm/set-variables@v1.0 + with: + # Name of variable file + variableFileName: 'variables.module' # Don't write .json here + - name: "Publish module" + uses: ./.github/actions/templates/publishModule + with: + templateFilePath: '${{ env.modulePath }}/deploy.json' + componentTemplateSpecRGName: '${{ env.componentTemplateSpecRGName }}' + componentTemplateSpecRGLocation: '${{ env.componentTemplateSpecRGLocation }}' + componentTemplateSpecName: '${{ env.moduleName }}' + componentTemplateSpecDescription: '${{ env.componentTemplateSpecDescription }}' + publishToTemplateSpec: '${{ env.publishToTemplateSpec }}' + versioningOption: '${{ github.event.inputs.versioningOption }}' + customVersion: '${{ github.event.inputs.customVersion }}' + + ############## + # REMOVE # + ############## + job_remove_module: + runs-on: ubuntu-20.04 + name: "Remove module" + if: ${{ github.event.inputs.removeDeployment == 'true' }} + needs: + - job_deploy_module + steps: + - name: "Checkout" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set environment variables + uses: deep-mm/set-variables@v1.0 + with: + # Name of variable file + variableFileName: 'variables.module' # Don't write .json here + - name: "Remove module" + uses: ./.github/actions/templates/removeModule + with: + moduleName: '${{ env.moduleName }}' + templateFilePath: '${{ env.modulePath }}/deploy.json' + resourceGroupName: '${{ env.resourceGroupName }}' \ No newline at end of file