Skip to content

AWX Update E2E Server #325

AWX Update E2E Server

AWX Update E2E Server #325

name: AWX Update E2E Server
on:
workflow_dispatch:
inputs:
AWX_SERVER:
type: string
description: 'AWX Server'
UPDATE_SERVER:
type: boolean
required: true
default: false
description: 'Update server on success'
schedule:
- cron: '0 8 * * *'
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
AWX_SERVER: ${{ steps.step1.outputs.AWX_SERVER }}
UPDATE_SERVER: ${{ steps.step1.outputs.UPDATE_SERVER }}
steps:
- id: step1
run: |
CURRENTDATE=$(date +'%Y%m%d')
if([ "${{ github.event_name }}" == "workflow_dispatch" ]); then
echo "AWX_SERVER=${{ github.event.inputs.AWX_SERVER || 'https://awx.ci-ui-${CURRENTDATE}.gcp.testing.ansible.com' }}" >> "$GITHUB_OUTPUT"
echo "UPDATE_SERVER=${{ github.event.inputs.UPDATE_SERVER }}" >> "$GITHUB_OUTPUT"
else
echo "AWX_SERVER=https://awx.ci-ui-${CURRENTDATE}.gcp.testing.ansible.com" >> "$GITHUB_OUTPUT"
echo "UPDATE_SERVER=true" >> "$GITHUB_OUTPUT"
fi
awx-login:
name: AWX Login
needs: setup
runs-on: ubuntu-latest
steps:
- id: login
env:
AWX_USERNAME: e2e
run: |
if curl -k -f "${{ needs.setup.outputs.AWX_SERVER }}/api/v2/users/" \
--user "$AWX_USERNAME:${{ secrets.AWX_PASSWORD }}" \
-o /dev/null; then
echo "UPDATE_SERVER=true" >> "$GITHUB_OUTPUT"
else
echo "UPDATE_SERVER=false" >> "$GITHUB_OUTPUT"
exit 1
fi
awx-update-server:
name: AWX Update Server
if: ${{ needs.setup.outputs.UPDATE_SERVER == 'true' }}
needs:
- awx-login
- setup
runs-on: ubuntu-latest
steps:
- name: Update Server Variable
run: |
curl -f -L -X PATCH -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/actions/variables/AWX_SERVER" \
-d '{"name":"AWX_SERVER","value":"${{ needs.setup.outputs.AWX_SERVER }}"}'
- name: Slack Notification
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"attachments":
[
{
"color": "#00DD00",
"blocks":
[
{
"type": "section",
"text":
{
"type": "mrkdwn",
"text": "*AWX E2E Server Updated*\n${{ github.repository }} - <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Success> - <${{ needs.setup.outputs.AWX_SERVER }}|Server>"
}
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
slack-failure-notification:
name: Slack Failure Notification
if: failure()
needs:
- awx-update-server
- setup
runs-on: ubuntu-latest
steps:
- name: Slack Notification
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"attachments":
[
{
"color": "#FF0000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*AWX E2E Server Update Failed*\n${{ github.repository }} - *<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Failure>* - <${{ needs.setup.outputs.AWX_SERVER }}|Server> - <!here>"
}
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK