Skip to content

Commit

Permalink
testing old packaging format
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-courtney-pieces committed May 22, 2024
1 parent 451c44f commit 19f997c
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 33 deletions.
68 changes: 37 additions & 31 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

jobs:
build:
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
### Checking out our Repo
- uses: actions/checkout@v3
Expand All @@ -35,46 +35,52 @@ jobs:
run: echo "VERSION=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_OUTPUT

### Generating our staging version number if we are not production
- name: Get staging version
shell: bash
id: staging_version
run: echo "STAGING_VERSION=$(/bin/bash staging_versioning.sh)" >> $GITHUB_OUTPUT
if: inputs.deploy == false
# - name: Get staging version
# shell: bash
# id: staging_version
# run: echo "STAGING_VERSION=$(/bin/bash staging_versioning.sh)" >> $GITHUB_OUTPUT
# if: inputs.deploy == false


### Setting the version in the pyproject.toml for unix builds
- name: Set Version Shell Script
run: |
if [[ ${{ steps.get_version.outputs.VERSION }} =~ [0-9]+.[0-9]+.[0-9]+$ ]]
then
echo "This is a tagged build"
export RELEASE_VERSION='${{ steps.get_version.outputs.VERSION }}'
RELEASE_VERSION="${RELEASE_VERSION#v}"
echo $RELEASE_VERSION
sed -i 's/__version__ = .*/__version__ = "${RELEASE_VERSION}"/' _version.py
else
echo "This is not a tagged build"
export STAGING_VERSION='${{ steps.staging_version.outputs.STAGING_VERSION }}'
sed -i 's/__version__ = .*/__version__ = "${STAGING_VERSION}"/' _version.py
fi
# - name: Set Version Shell Script
# run: |
# if [[ ${{ steps.get_version.outputs.VERSION }} =~ [0-9]+.[0-9]+.[0-9]+$ ]]
# then
# echo "This is a tagged build"
# export RELEASE_VERSION='${{ steps.get_version.outputs.VERSION }}'
# RELEASE_VERSION="${RELEASE_VERSION#v}"
# echo $RELEASE_VERSION
# sed -i 's/__version__ = .*/__version__ = "${RELEASE_VERSION}"/' _version.py
# else
# echo "This is not a tagged build"
# export STAGING_VERSION='${{ steps.staging_version.outputs.STAGING_VERSION }}'
# sed -i 's/__version__ = .*/__version__ = "${STAGING_VERSION}"/' _version.py
# fi

### Uploading our staging version text file to be pulled down later
- uses: actions/upload-artifact@v3
with:
name: staging_version
path: "*.txt"
if: inputs.deploy == false

# Zip repository contents into Pieces.sublime-package
- name: Zip Repository
# - uses: actions/upload-artifact@v3
# with:
# name: staging_version
# path: "*.txt"
# if: inputs.deploy == false

# Compress repository contents into Pieces.sublime-package
- name: Compress Repository
run: |
zip -r Pieces.sublime-package .
sudo rsync -av --iconv=utf-8 --progress ./* ./Pieces --exclude .gitignore --exclude .github --exclude .git --exclude artifacts
sudo cp ./.python-version Pieces/.python-version
sudo iconv -t utf-8 Pieces/.python-version
sudo python3 package.py Packing
- name: List what is in here
run: ls -la

### Pushing the built packages to GCP and GitHub
push-build:
runs-on: ubuntu-latest
needs:
- build
- not_now
steps:

### Pulling down the previously built plugins
Expand Down Expand Up @@ -167,7 +173,7 @@ jobs:
uses: softprops/action-gh-release@v1
if: inputs.deploy == true
with:
files: Pieces.sublime-package
files: Pieces.sublime-package
fail_on_unmatched_files: true
name: ${{ env.releasetag }}
tag_name: ${{ env.releasetag }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- testing_ci

jobs:
build:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
Pieces/
Pieces.sublime-package
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8
3.12.1
83 changes: 83 additions & 0 deletions package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
print("This script copyright [email protected]")

import sys
import os
import re
import zipfile
import compileall
from fnmatch import fnmatch

n = str(sys.argv[1])
print(n)

# The Package Name
package_name = "Pieces"

# Stores Pieces.sublime-package in dir higher
package_destination = "../"

# None ~ Uses Default Settings
profile=None

# Referencing entire repo (where script lives)
package_dir = "."

# Extension
package_filename = package_name + '.sublime-package'

# Where the compiled package will live
package_path = os.path.join(package_destination, package_filename)

if os.path.exists(package_path):
os.remove(package_path)

# Real Important Zip compression logic
package_file = zipfile.ZipFile(package_path, "w", compression=zipfile.ZIP_DEFLATED)

# This must be done exactly like this
# Refer to https://github.com/wbond/package_control/blob/cfaaeb57612023e3679ecb7f8cd7ceac9f57990d/package_control/package_manager.py#L886
# (Hopefully the above file still exists)
compileall.compile_dir(package_dir, quiet=True, legacy=True, optimize=2)

#Keeping these blank, can probs remove but will have to spend time figureing out if it will break code below
dirs_to_ignore = []
files_to_ignore = []
files_to_include = []

slash = '\\' if os.name == 'nt' else '/'
trailing_package_dir = package_dir + slash if package_dir[-1] != slash else package_dir
package_dir_regex = re.compile('^' + re.escape(trailing_package_dir))
for root, dirs, files in os.walk(package_dir):
# add "dir" to "paths" list if "dir" is not in "dirs_to_ignore"
dirs[:] = [x for x in dirs if x not in dirs_to_ignore]
paths = dirs
paths.extend(files)
for path in paths:
full_path = os.path.join(root, path)
relative_path = re.sub(package_dir_regex, '', full_path)

ignore_matches = [fnmatch(relative_path, p) for p in files_to_ignore]

include_matches = [fnmatch(relative_path, p) for p in files_to_include]

# This is probably done when Package Control rips settings from sublime.py (which references sublime_api.py which is closed sources)
if ".pyc" in relative_path:
continue

# Don't include this script in the package
if "package.py" in relative_path:
continue

#Probably Does what is mentioned above
if any(ignore_matches) and not any(include_matches):
continue

# Ditto
if os.path.isdir(full_path):
continue

# Yee'ol write
package_file.write(full_path, relative_path)

# We done here
package_file.close()

0 comments on commit 19f997c

Please sign in to comment.