Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split python into separate script #4

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Changed
- "Dogfood" action to check itself
- Move python code out of workflow file

## [v1.0.0] - 2024-04-18

Expand Down
27 changes: 6 additions & 21 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,21 @@ runs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.10'

# https://github.com/orgs/community/discussions/9049#discussioncomment-4239509
# Due to limitations on composite Actions, we can't do something like:
# - uses: docker://ghcr.io/uclahs-cds/cicd-base:${{ inputs.docker-tag }}
# Instead, we need to write another action.yml on-the-fly and then use that.
# There absolutely should not be an 'action.yml' file underneath the .git
# folder of the calling repository already, so we can use that.
- name: Configure workflow
shell: python
env:
DOCKER_IMAGE_TAG: ${{ inputs.docker-tag }}
run: |
import os
import re
from pathlib import Path

# Bail out if there are any illegal characters in the tag
tag = os.environ.get("DOCKER_IMAGE_TAG")
if re.search(r"[^a-zA-Z0-9_.\-]", tag):
raise ValueError(f"Problem with the tag `{tag}`!")

template = Path(
os.environ.get("GITHUB_ACTION_PATH"), "template", "action.yml"
)

Path(".git/action.yml").write_text(
template.read_text(encoding="utf-8").replace(
"DOCKER_IMAGE_TAG", tag
),
encoding="utf-8"
)
shell: bash
run: python '${{ github.action_path }}/create_template.py'

- name: Run checks
uses: ./.git
20 changes: 20 additions & 0 deletions create_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
"Generate an action.yml file from the template."
import os
import re
from pathlib import Path

# Bail out if there are any illegal characters in the tag
tag = os.environ.get("DOCKER_IMAGE_TAG")
if re.search(r"[^a-zA-Z0-9_.\-]", tag):
raise ValueError(f"Problem with the tag `{tag}`!")

template = Path(os.environ.get("GITHUB_ACTION_PATH"), "template", "action.yml")
output_file = Path(os.environ.get("GITHUB_WORKSPACE"), ".git", "action.yml")

output_file.write_text(
template.read_text(encoding="utf-8").replace(
"DOCKER_IMAGE_TAG", tag
),
encoding="utf-8"
)