-
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.
- Loading branch information
1 parent
48d2b84
commit d0b78b4
Showing
2 changed files
with
173 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,171 @@ | ||
name: My PublicCode Workflow | ||
name: PublicCode and PublicOrganization Check and Update | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
check-and-update: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Update publiccode.yaml | ||
uses: OpenCatalogi/[email protected] | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Check and Update publiccode.yaml | ||
if: (!contains(github.repository, '.github')) | ||
run: | | ||
REPO_NAME="${{ github.event.repository.name }}" | ||
REPO_DESC="${{ github.event.repository.description }}" | ||
REPO_URL="${{ github.event.repository.html_url }}" | ||
REPO_HOMEPAGE="${{ github.event.repository.homepage }}" | ||
#REPO_TOPICS="${{ github.event.repository.topics }}" | ||
REPO_LICENSE="EUPL-1.2" | ||
REPO_CREATED_AT="${{ github.event.repository.created_at }}" | ||
REPO_VERSION="v.1.1.1" | ||
ORGANISATION_NAME="${{ github.event.organization.login }}" | ||
ORGANISATION_DESCRIPTION="${{ github.event.organization.description }}" | ||
ORGANISATION_GITID="${{ github.event.organization.id}}" | ||
ORGANISATION_URL="${{ github.event.organization.login }}" | ||
ORGANISATION_AVATAR="${{ github.organization.avatar_url }}" | ||
echo "Installing PyYAML..." | ||
pip install PyYAML | ||
echo "Updating publiccode.yaml..." | ||
python - <<END | ||
import yaml | ||
import json | ||
from datetime import datetime | ||
# Read existing publiccode.yaml | ||
try: | ||
with open("publiccode.yaml", "r") as f: | ||
data = yaml.safe_load(f) | ||
except FileNotFoundError: | ||
data = {} | ||
# Convert created_at to date format | ||
# created_at_date = datetime.fromisoformat("$REPO_CREATED_AT".replace("Z", "+00:00")).strftime('%Y-%m-%d') | ||
created_at_date = datetime.now().strftime('%Y-%m-%d') | ||
# Convert topics JSON string to Python list and then to comma-separated string | ||
# Update or append values | ||
if "$REPO_NAME" != "null" and "$REPO_NAME": | ||
data['name'] = "$REPO_NAME" | ||
if "$REPO_URL" != "null" and "$REPO_URL": | ||
data['url'] = "$REPO_URL" | ||
if "$REPO_DESC" != "null" and "$REPO_DESC": | ||
data['description'] = "$REPO_DESC" | ||
if "$REPO_HOMEPAGE" != "null" and "$REPO_HOMEPAGE": | ||
data['url'] = "$REPO_HOMEPAGE" | ||
#if "$REPO_TOPICS" != "null" and "$REPO_TOPICS": | ||
# data['topics'] = "$REPO_TOPICS" | ||
if "$REPO_LICENSE" != "null" and "$REPO_LICENSE": | ||
data['license'] = "$REPO_LICENSE" | ||
if "$REPO_VERSION" != "null" and "$REPO_VERSION": | ||
data['softwareVersion'] = "$REPO_VERSION" | ||
# Add releaseDate if not present | ||
if 'releaseDate' not in data: | ||
data['releaseDate'] = created_at_date | ||
# Create or update nested 'organisation' array | ||
if 'organisation' not in data: | ||
data['organisation'] = {} | ||
if "$ORGANISATION_NAME" != "null" and "$ORGANISATION_NAME": | ||
data['organisation']['name'] = "$ORGANISATION_NAME" | ||
if "$ORGANISATION_AVATAR" != "null" and "$ORGANISATION_AVATAR": | ||
data['organisation']['logo'] = "$ORGANISATION_AVATAR" | ||
if "$ORGANISATION_URL" != "null" and "$ORGANISATION_URL": | ||
data['organisation']['url'] = "$ORGANISATION_URL" | ||
if "$ORGANISATION_DESCRIPTION" != "null" and "$ORGANISATION_DESCRIPTION": | ||
data['organisation']['description'] = "$ORGANISATION_DESCRIPTION" | ||
# Create or update nested 'nl' array | ||
if 'nl' not in data: | ||
data['nl'] = {} | ||
# Write updated publiccode.yaml | ||
with open("publiccode.yaml", "w") as f: | ||
yaml.safe_dump(data, f) | ||
END | ||
- name: Check and Update opencatalogi.yaml | ||
if: (contains(github.repository, '.github')) | ||
run: | | ||
REPO_NAME="${{ github.event.repository.name }}" | ||
REPO_DESC="${{ github.event.repository.description }}" | ||
REPO_URL="${{ github.event.repository.html_url }}" | ||
REPO_HOMEPAGE="${{ github.event.repository.homepage }}" | ||
#REPO_TOPICS="${{ github.event.repository.topics }}" | ||
REPO_LICENSE="EUPL-1.2" | ||
REPO_CREATED_AT="${{ github.event.repository.created_at }}" | ||
ORGANISATION_NAME="${{ github.event.organization.login }}" | ||
ORGANISATION_DESCRIPTION="${{ github.event.organization.description }}" | ||
ORGANISATION_GITID="${{ github.event.organization.id}}" | ||
ORGANISATION_URL="${{ github.event.organization.login }}" | ||
ORGANISATION_AVATAR="${{ github.event.organization.avatar_url }}" | ||
echo "Installing PyYAML..." | ||
pip install PyYAML | ||
echo "Updating openCatalogi.yaml..." | ||
python - <<END | ||
import yaml | ||
import json | ||
from datetime import datetime | ||
# Read existing openCatalogi.yaml | ||
try: | ||
with open("openCatalogi.yaml", "r") as f: | ||
data = yaml.safe_load(f) | ||
except FileNotFoundError: | ||
data = {} | ||
if "$ORGANISATION_NAME" != "null" and "$ORGANISATION_NAME": | ||
data['name'] = "$ORGANISATION_NAME" | ||
if "$ORGANISATION_AVATAR" != "null" and "$ORGANISATION_AVATAR": | ||
data['logo'] = "$ORGANISATION_AVATAR" | ||
if "$ORGANISATION_URL" != "null" and "$ORGANISATION_URL": | ||
data['url'] = "$ORGANISATION_URL" | ||
if "$ORGANISATION_DESCRIPTION" != "null" and "$ORGANISATION_DESCRIPTION": | ||
data['description'] = "$ORGANISATION_DESCRIPTION" | ||
# Create or update nested 'nl' array | ||
if 'nl' not in data: | ||
data['nl'] = {} | ||
# Write updated openCatalogi.yaml | ||
with open("openCatalogi.yaml", "w") as f: | ||
yaml.safe_dump(data, f) | ||
END | ||
- name: Commit changes | ||
if: (!contains(github.repository, '.github')) | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add publiccode.yaml | ||
git commit -m "${{ github.workflow }}" || echo "No changes to commit" | ||
git push | ||
- name: Commit changes | ||
if: (contains(github.repository, '.github')) | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git pull | ||
git add openCatalogi.yaml | ||
git commit -m "${{ github.workflow }}" || echo "No changes to commit" | ||
git push | ||
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