Skip to content

OCT-2194: API Tests failures fixes #892

OCT-2194: API Tests failures fixes

OCT-2194: API Tests failures fixes #892

Workflow file for this run

---
name: 🔒 Destroy Environment
on:
workflow_call:
inputs:
env-type:
required: true
type: string
pull-request-id:
required: false
type: string
workflow-id:
required: false
type: string
delete-env:
required: false
default: true
type: boolean
pull_request:
types: [ closed ]
issue_comment:
types: [ created ]
env:
# ----------------------------------------------------------------------------
# CI/CD
ARGOCD_URL: "${{ secrets.ARGOCD_URL }}"
ARGOCD_ACCESS_TOKEN: "${{ secrets.ARGOCD_ACCESS_TOKEN }}"
GITLAB_PAT_OCTANT_K8S_DEVOPS_REPOSITORY_WRITE: "${{ secrets.GITLAB_PAT_OCTANT_K8S_DEVOPS_REPOSITORY_WRITE }}"
jobs:
destroy:
name: Destroy Environment
runs-on:
- general
if: (github.event_name == 'issue_comment' && contains(github.event.comment.body, '/destroy')) || github.event_name != 'issue_comment'
container:
image: registry.gitlab.com/golemfoundation/devops/container-builder/gitops-builder:2ea6d57c
credentials:
username: "doesnt-matter"
password: "${{ secrets.GITLAB_PAT_CONTAINER_BUILDER_DOCKER_IMAGES_READ }}"
steps:
- name: Get PR branch
uses: xt0rted/pull-request-comment-branch@v2
if: github.event_name == 'issue_comment'
id: comment-branch
- name: Check if user is an org member
uses: actions/github-script@v7
id: is-organization-member
with:
result-encoding: string
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
return (
await github.rest.orgs.listMembers({
org: 'golemfoundation'
})
).data.map(({login}) => login).includes('${{ github.event.comment.user.login }}').toString()
- name: Cancel workflow
if: ${{ github.event_name == 'issue_comment' && steps.is-organization-member.outputs.result == 'false' }}
run: |
echo '${{ github.event.comment.user.login }} is not a member of the golemfoundation org'
exit 1
- uses: actions/github-script@v7
id: get-pr-number
if: github.event_name == 'issue_comment'
with:
result-encoding: string
script: |
return (
await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: '${{ steps.comment-branch.outputs.head_sha }}',
owner: context.repo.owner,
repo: context.repo.repo,
})
).data[0].number;
- uses: actions/checkout@v4.1.0
if: github.event_name == 'issue_comment'
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
- uses: actions/checkout@v4.1.0
if: github.event_name != 'issue_comment'
- name: Set up Gitops mutex
uses: ben-z/gh-action-mutex@v1.0.0-alpha.9
with:
branch: gitops-mutex
- name: Destroy application
id: destroy-env
run: |
set -ex
export CI_PROJECT_DIR="${GITHUB_WORKSPACE}"
export ENV_TYPE=${{ inputs.env-type }}
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
export CI_MERGE_REQUEST_IID=${{ github.event.number }}
export CI_PIPELINE_ID=${{ github.run_id }}
elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then
export CI_MERGE_REQUEST_IID=${{ steps.get-pr-number.outputs.result }}
export CI_PIPELINE_ID=${{ github.run_id }}
else
export CI_MERGE_REQUEST_IID=${{ inputs.pull-request-id }}
export CI_PIPELINE_ID=${{ inputs.workflow-id }}
fi
source ${CI_PROJECT_DIR}/ci/argocd/resolve_env.sh $ENV_TYPE
bash ${CI_PROJECT_DIR}/ci/argocd/application.sh destroy
echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/github-script@v7
id: does-env-exist
if: always()
with:
result-encoding: string
script: |
try {
await github.rest.repos.getEnvironment({
owner: context.repo.owner,
repo: context.repo.repo,
environment_name: '${{ steps.destroy-env.outputs.DEPLOYMENT_ID }}',
});
return 'true';
} catch {
return 'false';
}
- name: Delete Environment
uses: bobheadxi/deployments@v1
if: ${{ (steps.does-env-exist.outputs.result == 'true') && (inputs.delete-env || github.event_name == 'pull_request' || github.event_name == 'issue_comment') }}
with:
step: delete-env
token: ${{ secrets.GH_BOT_TOKEN }}
env: ${{ steps.destroy-env.outputs.DEPLOYMENT_ID }}
- name: Deactivate Environment
uses: bobheadxi/deployments@v1
if: ${{ (steps.does-env-exist.outputs.result == 'true') && !inputs.delete-env }}
with:
step: deactivate-env
token: ${{ secrets.GH_BOT_TOKEN }}
env: ${{ steps.destroy-env.outputs.DEPLOYMENT_ID }}