mirror of
https://github.com/bartvdbraak/keyweave.git
synced 2025-04-28 15:21:21 +00:00
Merge pull request #40 from bartvdbraak/feat/e2e-bicep-precheck
Add Bicep Pre-check if we should skip deploying to Azure
This commit is contained in:
commit
9bd2de40a6
1 changed files with 59 additions and 49 deletions
108
.github/workflows/tests.yml
vendored
108
.github/workflows/tests.yml
vendored
|
@ -11,8 +11,40 @@ on:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
bicep-pre-check:
|
||||||
|
name: Bicep Pre-check
|
||||||
|
environment: bicep
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
deployed_tag_exists: ${{ steps.check_tag.outputs.DEPLOYED_TAG_EXISTS }}
|
||||||
|
no_changes: ${{ steps.check_changes.outputs.NO_CHANGES }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Fetch complete history
|
||||||
|
run: |
|
||||||
|
git fetch --prune --unshallow --tags
|
||||||
|
- name: Check for deployed tag
|
||||||
|
id: check_tag
|
||||||
|
run: |
|
||||||
|
if git rev-parse --verify deployed >/dev/null 2>&1; then
|
||||||
|
echo "DEPLOYED_TAG_EXISTS=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "LAST_DEPLOYED_COMMIT=$(git rev-list -n 1 deployed)" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "DEPLOYED_TAG_EXISTS=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
- name: Check for changes in bicep folder
|
||||||
|
id: check_changes
|
||||||
|
if: steps.check_tag.outputs.DEPLOYED_TAG_EXISTS == 'true'
|
||||||
|
run: |
|
||||||
|
if git diff --quiet ${{ steps.check_tag.outputs.LAST_DEPLOYED_COMMIT }} HEAD -- bicep/ ; then
|
||||||
|
echo "NO_CHANGES=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "NO_CHANGES=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
bicep:
|
bicep:
|
||||||
name: Deploy Azure resources
|
name: Deploy Azure resources
|
||||||
|
needs: bicep-pre-check
|
||||||
|
if: needs.bicep-pre-check.outputs.deployed_tag_exists == 'false' || needs.bicep-pre-check.outputs.no_changes == 'false'
|
||||||
environment: bicep
|
environment: bicep
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
concurrency:
|
concurrency:
|
||||||
|
@ -21,58 +53,36 @@ jobs:
|
||||||
LOCATION: eastus
|
LOCATION: eastus
|
||||||
DEPLOYMENT_NAME: keyweave-${{ github.run_id }}
|
DEPLOYMENT_NAME: keyweave-${{ github.run_id }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Fetch complete history
|
- uses: azure/login@v1
|
||||||
run: git fetch --prune --unshallow
|
with:
|
||||||
- name: Check for deployed tag
|
client-id: ${{ secrets.AZURE_CLIENT_ID }}
|
||||||
id: check_tag
|
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
||||||
run: |
|
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
|
||||||
if git rev-parse --verify deployed >/dev/null 2>&1; then
|
- name: Deploy Bicep template
|
||||||
echo "DEPLOYED_TAG_EXISTS=true" >> $GITHUB_ENV
|
uses: azure/arm-deploy@v1
|
||||||
echo "LAST_DEPLOYED_COMMIT=$(git rev-list -n 1 deployed)" >> $GITHUB_ENV
|
with:
|
||||||
else
|
scope: subscription
|
||||||
echo "DEPLOYED_TAG_EXISTS=false" >> $GITHUB_ENV
|
region: ${{ env.LOCATION }}
|
||||||
fi
|
template: bicep/main.bicep
|
||||||
- name: Check for changes in bicep folder
|
deploymentName: ${{ env.DEPLOYMENT_NAME }}
|
||||||
if: env.DEPLOYED_TAG_EXISTS == 'true'
|
- name: Tag Deployment
|
||||||
run: |
|
run: |
|
||||||
if git diff --quiet $LAST_DEPLOYED_COMMIT HEAD -- bicep/ ; then
|
git config --global user.name "github-actions[bot]"
|
||||||
echo "NO_CHANGES=true" >> $GITHUB_ENV
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
else
|
git tag -fa deployed -m "Deployed to Azure"
|
||||||
echo "NO_CHANGES=false" >> $GITHUB_ENV
|
git push origin --tags --force
|
||||||
fi
|
|
||||||
- if: env.DEPLOYED_TAG_EXISTS == 'false' || env.NO_CHANGES == 'false'
|
|
||||||
uses: azure/login@v1
|
|
||||||
with:
|
|
||||||
client-id: ${{ secrets.AZURE_CLIENT_ID }}
|
|
||||||
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
|
||||||
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
|
|
||||||
- if: env.DEPLOYED_TAG_EXISTS == 'false' || env.NO_CHANGES == 'false'
|
|
||||||
name: Deploy Bicep template
|
|
||||||
uses: azure/arm-deploy@v1
|
|
||||||
with:
|
|
||||||
scope: subscription
|
|
||||||
region: ${{ env.LOCATION }}
|
|
||||||
template: bicep/main.bicep
|
|
||||||
deploymentName: ${{ env.DEPLOYMENT_NAME }}
|
|
||||||
- if: env.DEPLOYED_TAG_EXISTS == 'false' || env.NO_CHANGES == 'false'
|
|
||||||
name: Tag Deployment
|
|
||||||
run: |
|
|
||||||
git config --global user.name "github-actions[bot]"
|
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
||||||
git tag -fa deployed -m "Deployed to Azure"
|
|
||||||
git push origin --tags --force
|
|
||||||
|
|
||||||
tests-no-access:
|
tests-no-access:
|
||||||
name: Tests with No Access
|
name: Tests with No Access
|
||||||
needs: bicep
|
needs: bicep
|
||||||
|
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: test
|
environment: test
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
- name: 'Az CLI login'
|
- uses: azure/login@v1
|
||||||
uses: azure/login@v1
|
|
||||||
with:
|
with:
|
||||||
client-id: ${{ secrets.AZURE_CLIENT_ID_NO_ACCESS }}
|
client-id: ${{ secrets.AZURE_CLIENT_ID_NO_ACCESS }}
|
||||||
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
||||||
|
@ -82,13 +92,13 @@ jobs:
|
||||||
tests-get:
|
tests-get:
|
||||||
name: Tests with Get
|
name: Tests with Get
|
||||||
needs: bicep
|
needs: bicep
|
||||||
|
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: test
|
environment: test
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
- name: 'Az CLI login'
|
- uses: azure/login@v1
|
||||||
uses: azure/login@v1
|
|
||||||
with:
|
with:
|
||||||
client-id: ${{ secrets.AZURE_CLIENT_ID_GET }}
|
client-id: ${{ secrets.AZURE_CLIENT_ID_GET }}
|
||||||
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
||||||
|
@ -98,13 +108,13 @@ jobs:
|
||||||
tests-list:
|
tests-list:
|
||||||
name: Tests with List
|
name: Tests with List
|
||||||
needs: bicep
|
needs: bicep
|
||||||
|
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: test
|
environment: test
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
- name: 'Az CLI login'
|
- uses: azure/login@v1
|
||||||
uses: azure/login@v1
|
|
||||||
with:
|
with:
|
||||||
client-id: ${{ secrets.AZURE_CLIENT_ID_LIST }}
|
client-id: ${{ secrets.AZURE_CLIENT_ID_LIST }}
|
||||||
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
||||||
|
@ -114,13 +124,13 @@ jobs:
|
||||||
tests-get-list:
|
tests-get-list:
|
||||||
name: Tests with Get and List
|
name: Tests with Get and List
|
||||||
needs: bicep
|
needs: bicep
|
||||||
|
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: test
|
environment: test
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
- name: 'Az CLI login'
|
- uses: azure/login@v1
|
||||||
uses: azure/login@v1
|
|
||||||
with:
|
with:
|
||||||
client-id: ${{ secrets.AZURE_CLIENT_ID_GET_LIST }}
|
client-id: ${{ secrets.AZURE_CLIENT_ID_GET_LIST }}
|
||||||
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
||||||
|
|
Loading…
Reference in a new issue