From 654ee378984e0cc97e2f84e6256cd97273a99be0 Mon Sep 17 00:00:00 2001 From: Anthony Rose <20302208+Cx01N@users.noreply.github.com> Date: Thu, 2 May 2024 15:22:16 +0000 Subject: [PATCH 1/2] Added action to update *.py files --- .github/workflows/update_files.yml | 99 ++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .github/workflows/update_files.yml diff --git a/.github/workflows/update_files.yml b/.github/workflows/update_files.yml new file mode 100644 index 0000000..276acb1 --- /dev/null +++ b/.github/workflows/update_files.yml @@ -0,0 +1,99 @@ +name: Update files + +on: + workflow_dispatch: + +jobs: + prepare-release: + runs-on: ubuntu-latest + steps: + - name: Checkout Main Repository + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + ref: main + + - name: Checkout SharpCollection Repository + uses: actions/checkout@v4.1.1 + with: + repository: Flangvik/SharpCollection + path: SharpCollection + ref: master + + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version: '3.x' + + - name: Process Executables for .NET 4.0 + run: | + mkdir -p SharpCollection_new/NetFramework_4.0_Any + cp -v -r SharpCollection/NetFramework_4.0_Any/ SharpCollection_new/ + ls -la SharpCollection_new/ + python IronEmbed.py SharpCollection_new/NetFramework_4.0_Any SharpCollection_new/NetFramework_4.0_Any + cp -v -f SharpCollection_new/NetFramework_4.0_Any/*.py NetFramework_4.0_Any/ + + - name: Process Executables for .NET 4.5 + run: | + mkdir -p SharpCollection_new/NetFramework_4.5_Any + cp -v -r SharpCollection/NetFramework_4.5_Any/ SharpCollection_new/ + ls -la SharpCollection_new/ + python IronEmbed.py SharpCollection_new/NetFramework_4.5_Any SharpCollection_new/NetFramework_4.5_Any + cp -v -f SharpCollection_new/NetFramework_4.5_Any/*.py NetFramework_4.5_Any/ + + - name: Process Executables for .NET 4.7 + run: | + mkdir -p SharpCollection_new/NetFramework_4.7_Any + cp -v -r SharpCollection/NetFramework_4.7_Any/ SharpCollection_new/ + ls -la SharpCollection_new/ + python IronEmbed.py SharpCollection_new/NetFramework_4.7_Any SharpCollection_new/NetFramework_4.7_Any + cp -v -f SharpCollection_new/NetFramework_4.7_Any/*.py NetFramework_4.7_Any/ + + - name: Remove unused files + run: | + rm -r -f SharpCollection_new + rm -r -f SharpCollection + + - name: Upload Python files as artifacts + uses: actions/upload-artifact@v2 + with: + name: generated-python-files + path: SharpCollection2/NetFramework_4.0_Any/*.py + + - name: Configure Git + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + - name: Set Environment Variables + run: echo "RELEASE_BRANCH=release-$(date +%Y-%m-%d)" >> $GITHUB_ENV + + - name: Delete Existing Branch if It Exists + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh auth setup-git + EXISTING_PR=$(gh pr list --head ${{ env.RELEASE_BRANCH }} --base main --state open --json url --jq '.[].url') + if [ "$EXISTING_PR" != "" ]; then + gh pr close $EXISTING_PR --delete-branch + fi + + - name: Create New Branch + run: | + git checkout -b ${{ env.RELEASE_BRANCH }} + git add . + git commit -m "Add new release files for different .NET versions" + git push --set-upstream origin ${{ env.RELEASE_BRANCH }} + + - name: Push Branch + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ env.RELEASE_BRANCH }} + force: true + + - name: Create Pull Request using GitHub CLI + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr create --title "New Release: ${{ env.RELEASE_BRANCH }}" --body "Generated new release files for distribution across .NET Framework versions." --head ${{ env.RELEASE_BRANCH }} --base main From ae0599ec8616bdea7d3f3957cae202021e8fea9f Mon Sep 17 00:00:00 2001 From: Anthony Rose <20302208+Cx01N@users.noreply.github.com> Date: Thu, 2 May 2024 22:53:27 +0000 Subject: [PATCH 2/2] Added github actions for updating .py files and generating releases --- .github/ci-and-release.md | 25 +++++++++ .github/workflows/release.yml | 82 ++++++++++++++++++++++++++++++ .github/workflows/tag_release.yml | 74 +++++++++++++++++++++++++++ .github/workflows/update_files.yml | 30 ++++------- CHANGELOG.md | 26 ++++++++++ IronEmbed.py | 19 +++---- 6 files changed, 226 insertions(+), 30 deletions(-) create mode 100644 .github/ci-and-release.md create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tag_release.yml create mode 100644 CHANGELOG.md diff --git a/.github/ci-and-release.md b/.github/ci-and-release.md new file mode 100644 index 0000000..4fcfdf2 --- /dev/null +++ b/.github/ci-and-release.md @@ -0,0 +1,25 @@ +# CI Processes +## Update IronSharpPack .py files and Create PR (update_files.yml) +This workflow is manually triggered to update Python files based on executables from the SharpCollection repository. It processes these files, commits any changes, and creates a new branch and pull request into main. + +Key Steps: +1. Process Executables: Runs a Python script to generate Python files from .NET executables across different .NET Framework versions. +2. Remove Unused Files: Cleans up any temporary or unnecessary files created during the run. +3. Create New Branch and Handle Changes: Checks for changes and commits them to a new branch, pushing the branch and creating a pull request if changes exist. + + +## Update Development Branch and PR to Main (release.yml) +This workflow is triggered manually via workflow_dispatch with an option to specify the type of version bump (patch, minor, or major). It's designed to increment the project version based on the latest entry in CHANGELOG.md, update the changelog, commit these changes to the dev branch, and then create a pull request to merge these changes into the main branch. + +Key Steps: +1. Extract and Increment Version: It reads the current version from CHANGELOG.md, increments it based on the selected bump type, and then updates the environment variable for subsequent steps. +2. Update Changelog: Utilizes a community action to append the new version to CHANGELOG.md. +3. Commit Changes and Create Pull Request: Commits the updated changelog to dev and creates a pull request to merge dev into main. + +## Create Release and Attach Files (tag_release.yml) +Triggered when a pull request to the main branch is closed and merged. It packages specified directories into ZIP files, creates a GitHub release tagged with the version number extracted from CHANGELOG.md, and uploads the ZIP files as assets to the release. + +Key Steps: +1. Determine New Version: Parses CHANGELOG.md to find the latest version number. +2. Zip NetFramework folders: Compresses folders containing different versions of .NET Framework files into ZIP files. +3. Create Release and Upload Release Asset: Creates a new GitHub release with the specified version and uploads the previously zipped files as release assets. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..84fd84f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,82 @@ +name: Update Development Branch and PR to Main + +on: + workflow_dispatch: + inputs: + bumpType: + description: 'Select the bump type for the next release.' + type: choice + default: patch + options: + - patch + - minor + - major + required: true + +jobs: + update_dev: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + ref: dev + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Initialize mandatory git config + run: | + git config user.name "GitHub Actions" + git config user.email noreply@github.com + + - name: Extract and increment version + id: versioning + run: | + # Extract the latest version from CHANGELOG.md + VERSION=$(grep -Po '(?<=\[)\d+\.\d+\.\d+(?=\])' CHANGELOG.md | head -1) + echo "Current version: $VERSION" + + # Increment version based on input type + IFS='.' read -ra VER <<< "$VERSION" + MAJOR=${VER[0]} + MINOR=${VER[1]} + PATCH=${VER[2]} + + if [ "${{ github.event.inputs.bumpType }}" == "major" ]; then + MAJOR=$((MAJOR + 1)) + MINOR=0 + PATCH=0 + elif [ "${{ github.event.inputs.bumpType }}" == "minor" ]; then + MINOR=$((MINOR + 1)) + PATCH=0 + else + PATCH=$((PATCH + 1)) + fi + + NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV + echo "::set-output name=new_version::$NEW_VERSION" + + - name: Print new version + run: echo "New version is ${{ steps.versioning.outputs.new_version }}" + + - name: Update Changelog + uses: vinnybod/keep-a-changelog-new-release@1.4.0 + with: + version: ${{ steps.versioning.outputs.new_version }} + + - name: Commit changes + run: | + git add . + git commit -m "Update changelog for release v${{ steps.versioning.outputs.new_version }}" + git push + + - name: Create pull request from dev to main + uses: repo-sync/pull-request@v2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + pr_title: "Release v${{ steps.versioning.outputs.new_version }} into main" + pr_body: "This PR was automatically generated to roll out new changes into main. Please merge with a merge commit." + pr_label: "release" + destination_branch: "main" + source_branch: "dev" \ No newline at end of file diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml new file mode 100644 index 0000000..c409ff7 --- /dev/null +++ b/.github/workflows/tag_release.yml @@ -0,0 +1,74 @@ +name: Create Release and Attach Files + +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + create_release: + if: ${{ github.event.pull_request.merged == true }} + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Determine new version + run: | + # Extract the latest version number from Changelog.md + VERSION=$(grep -Po '(?<=\[)\d+\.\d+\.\d+(?=\])' CHANGELOG.md | head -1) + echo "Current version: $VERSION" + echo "APP_VERSION=$VERSION" >> $GITHUB_ENV + + - name: Zip NetFramework folders + run: | + zip -r NetFramework_4.0_Any.zip NetFramework_4.0_Any/ + zip -r NetFramework_4.5_Any.zip NetFramework_4.5_Any/ + zip -r NetFramework_4.7_Any.zip NetFramework_4.7_Any/ + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ env.APP_VERSION }} + release_name: Release v${{ env.APP_VERSION }} + body: Release of version ${{ env.APP_VERSION }} + draft: false + prerelease: false + + - name: Upload Release Asset for NetFramework 4.0 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./NetFramework_4.0_Any.zip + asset_name: NetFramework_4.0_Any.zip + asset_content_type: application/zip + + - name: Upload Release Asset for NetFramework 4.5 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./NetFramework_4.5_Any.zip + asset_name: NetFramework_4.5_Any.zip + asset_content_type: application/zip + + - name: Upload Release Asset for NetFramework 4.7 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./NetFramework_4.7_Any.zip + asset_name: NetFramework_4.7_Any.zip + asset_content_type: application/zip \ No newline at end of file diff --git a/.github/workflows/update_files.yml b/.github/workflows/update_files.yml index 276acb1..a8956ff 100644 --- a/.github/workflows/update_files.yml +++ b/.github/workflows/update_files.yml @@ -1,4 +1,4 @@ -name: Update files +name: Update IronSharpPack .py files and Create PR on: workflow_dispatch: @@ -53,12 +53,6 @@ jobs: run: | rm -r -f SharpCollection_new rm -r -f SharpCollection - - - name: Upload Python files as artifacts - uses: actions/upload-artifact@v2 - with: - name: generated-python-files - path: SharpCollection2/NetFramework_4.0_Any/*.py - name: Configure Git run: | @@ -78,22 +72,16 @@ jobs: gh pr close $EXISTING_PR --delete-branch fi - - name: Create New Branch + - name: Create New Branch and Handle Changes run: | git checkout -b ${{ env.RELEASE_BRANCH }} git add . - git commit -m "Add new release files for different .NET versions" - git push --set-upstream origin ${{ env.RELEASE_BRANCH }} - - - name: Push Branch - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ env.RELEASE_BRANCH }} - force: true - - - name: Create Pull Request using GitHub CLI + if ! git diff --cached --exit-code; then + git commit -m "Add new release files for different .NET versions" + git push --set-upstream origin ${{ env.RELEASE_BRANCH }} + gh pr create --title "New Release: ${{ env.RELEASE_BRANCH }}" --body "Generated new release files for distribution across .NET Framework versions." --head ${{ env.RELEASE_BRANCH }} --base main + else + echo "No changes to commit, skipping push and pull request creation." + fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh pr create --title "New Release: ${{ env.RELEASE_BRANCH }}" --body "Generated new release files for distribution across .NET Framework versions." --head ${{ env.RELEASE_BRANCH }} --base main diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..fd41d4b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,26 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +- **Added** for new features. +- **Changed** for changes in existing functionality. +- **Deprecated** for soon-to-be removed features. +- **Removed** for now removed features. +- **Fixed** for any bug fixes. +- **Security** in case of vulnerabilities. + +## [Unreleased] + +### Added +- Added Github actions to automate updating of .py files +- Added Github release action to automate changelog, tagging, and release processes + +### Changed +- Updated IronEmbed.py to work with new actions + +## [1.0.0] - 2024-04-18 + +- Initial release diff --git a/IronEmbed.py b/IronEmbed.py index 50acd00..d78cda3 100644 --- a/IronEmbed.py +++ b/IronEmbed.py @@ -3,33 +3,34 @@ import base64 import zlib - def file_to_base64_compressed(file_path): with open(file_path, 'rb') as file: compressed_data = zlib.compress(file.read()) base64_encoded = base64.b64encode(compressed_data).decode('utf-8') return base64_encoded - def main(): - if len(sys.argv) < 2 or sys.argv[1] == 'help': + # Check for minimum required arguments and help command + if len(sys.argv) < 3 or sys.argv[1] == 'help': print('''IronEmbed compresses a .NET assembly and embeds it into an IronPython script - arguments should be ''') + Usage: python IronEmbed.py ''') return assembly_dir = sys.argv[1] + output_dir = sys.argv[2] + remove_comments_flag = '--remove-comments' in sys.argv + for file_name in os.listdir(assembly_dir): if file_name.endswith('.exe') or file_name.endswith('.dll'): - file_path = os.path.join(assembly_dir, file_name) compressed_assembly = file_to_base64_compressed(file_path) - + with open('IronSharpPack_template.py', 'r') as file: script = file.read() script = script.replace("", compressed_assembly) - script = script.replace("", file_name.replace('.exe', '')) - - out_name = "Iron" + file_name.replace('.exe', '.py').replace('.dll', '.py') + script = script.replace("", file_name.replace('.exe', '').replace('.dll', '')) + + out_name = os.path.join(output_dir, "Iron" + file_name.replace('.exe', '.py').replace('.dll', '.py')) with open(out_name, 'w') as out_file: out_file.write(script)