-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* generic curl * refactor * upgrade to 2.319.1 * build now works * update some components * try vars * fix the action inputs * fix the action inputs * another typo * add the token * requirements * GH_AUTH_TOKEN added * fix one more token * try a different repo * move to github variables * fix the inputs * more fixes of variables * fix the action inputs * remember the backslashes * proper runner labels * fix the action inputs * ready runner * fix the action inputs * github_repository change * try with a different repository * try a different token * get the right app ID * fix the access token for offline runners cleanup * ready to PR fo production * two runners let's go for it * only deploy to prod
- Loading branch information
1 parent
7cd71a5
commit 806af2e
Showing
10 changed files
with
143 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: 'Remove offline runners' | ||
description: 'action to remove offline runners' | ||
inputs: | ||
gh_auth_token: | ||
description: 'Token used to authenticate to Github' | ||
qty_runners: | ||
description: 'Number of expected runners' | ||
default: '1' | ||
github_repository: | ||
description: 'The repository in which the runners are deployed' | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: clean up runners | ||
shell: python {0} | ||
id: cleanup-runners | ||
run: | | ||
from github import Auth | ||
from github import Github | ||
from github import GithubException | ||
import os | ||
from time import sleep | ||
# Attempts to remove any offline runners - giving time for old ones to expire | ||
def main(): | ||
expected_number_of_runners=os.getenv('qty_runners',1) | ||
github_repository=os.getenv('github_repository') | ||
auth = Auth.Token(os.getenv('gh_auth_token')) | ||
print(f'Repo name is: {github_repository}') | ||
g = Github(auth=auth) | ||
repo = g.get_repo(github_repository) | ||
offline_deleted=False | ||
qty_runners=retry_count=0 | ||
while qty_runners!=expected_number_of_runners and retry_count < 10: | ||
try: | ||
runners = repo.get_self_hosted_runners() | ||
qty_runners=runners.totalCount | ||
print(f'Attempt to clean up offline runners: {retry_count} - found {qty_runners} runners') | ||
for each_runner in runners: | ||
print(f'Checking runner {each_runner.name} with status {each_runner.status}') | ||
if each_runner.status == 'offline': | ||
success=repo.remove_self_hosted_runner(each_runner.id) | ||
except: | ||
print(f'Failed because {GithubException.message}') | ||
retry_count+=1 | ||
sleep(10) | ||
if __name__ == '__main__': | ||
main() | ||
env: | ||
github_repository: ${{ inputs.github_repository }} | ||
gh_auth_token: ${{ inputs.gh_auth_token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ on: | |
|
||
env: | ||
push: ${{ inputs.push }} | ||
ghcr_token: ${{ secrets.GHCR_TOKEN}} | ||
|
||
jobs: | ||
build-docker: | ||
|
@@ -41,10 +42,18 @@ jobs: | |
version=$(date '+%Y-%m-%d').${{ github.run_number }}.$(echo ${{ github.sha }} | cut -c1-7) | ||
echo "version=$version" | tee -a "$GITHUB_OUTPUT" | ||
- name: GitHub app JWT and installation access token generation | ||
uses: jamestrousdale/[email protected] | ||
id: generate-github-app-tokens | ||
with: | ||
app-id: ${{ vars.GH_APP_ID }} | ||
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} | ||
|
||
- name: Build Docker images | ||
uses: ./.github/actions/docker-build | ||
id: build | ||
with: | ||
project: ${{ matrix.project }} | ||
push: ${{ env.push }} | ||
version: ${{ steps.version.outputs.version }} | ||
gh_auth_token: ${{ steps.generate-github-app-tokens.outputs.access-token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ jobs: | |
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
|
||
environment: | ||
name: ${{ inputs.environment }} | ||
steps: | ||
|
@@ -41,6 +40,13 @@ jobs: | |
with: | ||
environment: ${{ inputs.environment }} | ||
|
||
- name: GitHub app JWT and installation access token generation | ||
uses: jamestrousdale/[email protected] | ||
id: generate-github-app-tokens | ||
with: | ||
app-id: ${{ vars.GH_APP_ID }} | ||
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} | ||
|
||
- name: Deploy to Platform | ||
uses: ./.github/actions/cloud-platform-deploy | ||
with: | ||
|
@@ -51,3 +57,13 @@ jobs: | |
cluster: ${{ secrets.KUBE_CLUSTER }} | ||
namespace: ${{ secrets.KUBE_NAMESPACE }} | ||
token: ${{ secrets.KUBE_TOKEN }} | ||
gh_auth_token: ${{ steps.generate-github-app-tokens.outputs.access-token }} | ||
github_repository: ${{ vars.GH_REPOSITORY }} | ||
runner_labels: ${{ vars.RUNNER_LABELS }} | ||
|
||
- name: Remove offline runners | ||
uses: ./.github/actions/runner-cleanup | ||
with: | ||
gh_auth_token: ${{ steps.generate-github-app-tokens.outputs.access-token }} | ||
github_repository: ${{ vars.GH_REPOSITORY }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PyGithub>=2.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters