Skip to content

Update build.js to automatically increment the version number #194

Update build.js to automatically increment the version number

Update build.js to automatically increment the version number #194

name: React App Tabs to Test
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
outputs:
deploymentUrl: ${{ steps.builddeploy.outputs.deploymentUrl }}
permissions:
contents: read
pull-requests: write
environment: Test
name: Build and Deploy Job
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: false
lfs: false
- name: Run preinstall script
run: npx npm-force-resolutions
- name: Install dependencies
run: npm install
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
env:
CI: false
REACT_APP_LNBITS_NODE_URL: ${{ secrets.LNBITS_NODE_URL }}
REACT_APP_LNBITS_USERNAME: ${{ secrets.LNBITS_USERNAME }}
REACT_APP_LNBITS_PASSWORD: ${{ secrets.LNBITS_PASSWORD }}
REACT_APP_LNBITS_ADMINKEY: ${{ secrets.LNBITS_ADMINKEY }}
REACT_APP_LNBITS_STORE_ID: ${{ secrets.LNBITS_STORE_ID }}
REACT_APP_TENANT_ID: ${{ secrets.TENANT_ID }}
REACT_APP_AAD_CLIENT_ID: ${{ secrets.AAD_CLIENT_ID }}
REACT_APP_LNBITS_STORE_OWNER_EMAIL: ${{ secrets.LNBITS_STORE_OWNER_EMAIL }}
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: 'upload'
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: '/tabs' # App source code path
api_location: '' # Api source code path - optional
output_location: 'build' # Built app content directory - optional
###### End of Repository/Build Configurations ######
- name: Install Azure CLI
run: |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# Login to Azure
- name: Login to Azure
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Add Redirect URI
if: github.event_name == 'pull_request'
run: |
$currentRedirectUris = az rest --method "get" --uri "https://graph.microsoft.com/v1.0/applications/6f3836b2-9449-45e7-aa62-810cbeaa6c5d" --headers '{"Content-Type": "application/json"}' -o json --query "spa.redirectUris"
$newRedirectUri = "${{ steps.builddeploy.outputs.static_web_app_url }}"
$updatedRedirectUris = $currentRedirectUris | ConvertFrom-Json
if ($updatedRedirectUris -notcontains $newRedirectUri) {
$updatedRedirectUris += $newRedirectUri
$updatedRedirectUrisJson = $updatedRedirectUris | ConvertTo-Json -Depth 10 -Compress
$jsonStringWithSingleQuotes = $updatedRedirectUrisJson -replace '"', "'"
az rest --method "patch" --uri "https://graph.microsoft.com/v1.0/applications/6f3836b2-9449-45e7-aa62-810cbeaa6c5d" --headers "{'Content-Type': 'application/json'}" --body "{'spa': {'redirectUris': $jsonStringWithSingleQuotes}}"
}
shell: pwsh
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Remove Redirect URI
run: |
$currentRedirectUris = az rest --method "get" --uri "https://graph.microsoft.com/v1.0/applications/6f3836b2-9449-45e7-aa62-810cbeaa6c5d" --headers '{"Content-Type": "application/json"}' -o json --query "spa.redirectUris"
$newRedirectUri = "${{ steps.builddeploy.outputs.static_web_app_url }}"
$updatedRedirectUris = $currentRedirectUris | ConvertFrom-Json
$updatedRedirectUris = $updatedRedirectUris | Where-Object { $_ -ne $newRedirectUri }
$updatedRedirectUrisJson = $updatedRedirectUris | ConvertTo-Json -Depth 10 -Compress
$jsonStringWithSingleQuotes = $updatedRedirectUrisJson -replace '"', "'"
az rest --method "patch" --uri "https://graph.microsoft.com/v1.0/applications/6f3836b2-9449-45e7-aa62-810cbeaa6c5d" --headers "{'Content-Type': 'application/json'}" --body "{'spa': {'redirectUris': $jsonStringWithSingleQuotes}}"
shell: pwsh
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: 'close'
app_location: '/tabs'