-
Notifications
You must be signed in to change notification settings - Fork 2
Dev #3
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
base: master
Are you sure you want to change the base?
Dev #3
Changes from all commits
c936d61
10b209e
fa3c02f
3aca76b
33d939c
72a4b75
12b0ee9
92d59c3
cb96f66
abe0f4d
9244f27
91a4183
810083f
c949dc0
905b3a2
ef9a059
a96acca
d8a4732
bf29771
8f27bfe
8324bf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||
| --- | ||||||
| name: ci | ||||||
|
|
||||||
| 'on': | ||||||
| push: | ||||||
| branches: | ||||||
| - '**' | ||||||
|
|
||||||
| permissions: | ||||||
| contents: write | ||||||
|
|
||||||
| jobs: | ||||||
| ci: | ||||||
| runs-on: [self-hosted, dev] | ||||||
| steps: | ||||||
| - name: Checkout | ||||||
| uses: actions/checkout@v4 | ||||||
|
|
||||||
| - name: Extras / Count Lines of Source Code | ||||||
| run: make extras/cloc | ||||||
|
|
||||||
| # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
| # Lint | ||||||
| # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
| - name: Lint | ||||||
| run: make format | ||||||
|
|
||||||
| - name: Check | ||||||
| run: git diff HEAD --quiet | ||||||
|
|
||||||
| # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
| # Build [Prod] (and Upload binary) | ||||||
| # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
| - name: Check release version | ||||||
| id: check-release-version | ||||||
| if: github.ref == 'refs/heads/master' | ||||||
| env: | ||||||
| GH_TOKEN: ${{ github.token }} | ||||||
| run: | | ||||||
| RELEASE_TAG=$(make deploy/get-current-db-version) | ||||||
| # Test that github-cli is working | ||||||
| gh --version | ||||||
| gh release list -L 1 | ||||||
| # TODO: enhance this to be: if release_tag > current_prod_tag, deploy. | ||||||
| # Otherwise, can skip this step entirely? | ||||||
| gh release view $RELEASE_TAG || echo "PUBLISH=1" >> "$GITHUB_OUTPUT" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Quote the $RELEASE_TAG variable to prevent word splitting and handle empty/special values safely. Prompt for AI agents
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: The release existence check is fragile. Prompt for AI agents |
||||||
| # yamllint disable rule:line-length | ||||||
| - name: Build (production release) | ||||||
| if: github.ref == 'refs/heads/master' && steps.check-release-version.outputs.PUBLISH | ||||||
| env: | ||||||
| GH_TOKEN: ${{ github.token }} | ||||||
| run: set -o pipefail; make build | ||||||
|
|
||||||
| - name: Upload artifacts (production release) | ||||||
| if: github.ref == 'refs/heads/master' && steps.check-release-version.outputs.PUBLISH | ||||||
| env: | ||||||
| GH_TOKEN: ${{ github.token }} | ||||||
| run: set -o pipefail; make deploy/upload | ||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| SHELL=/bin/bash | ||
|
|
||
| .DEFAULT_GOAL := _help | ||
|
|
||
| # NOTE: must put a <TAB> character and two pound "\t##" to show up in this list. Keep it brief! IGNORE_ME | ||
| .PHONY: _help | ||
| _help: | ||
| @grep -h "##" $(MAKEFILE_LIST) | grep -v IGNORE_ME | grep -v ^# | sed -e 's/##//' | column -t -s $$'\t' | ||
|
|
||
|
|
||
|
|
||
| # --------------------------------------- | ||
| # Format | ||
| # --------------------------------------- | ||
|
|
||
| .PHONY: format | ||
| format: ## format SQL with pg_format | ||
| # TODO: what about import.sql? It gets formatted too ugly | ||
| # TODO: what about Python files? | ||
| pg_format -L -s 2 -w 100 sql/tables.sql >sql/tables.fmt.sql | ||
| mv sql/tables.fmt.sql sql/tables.sql | ||
|
|
||
|
|
||
|
|
||
| # --------------------------------------- | ||
| # Build, test, and docs | ||
| # --------------------------------------- | ||
|
|
||
| DB_VERSION ?= $(shell python3 sql/latest_version.py) | ||
| DB_FILE ?= sql/usda.sqlite3 | ||
| DB_XZ_FILE ?= sql/dist/usda.sqlite3-${DB_VERSION}.tar.xz | ||
|
|
||
| .PHONY: build | ||
| build: clean | ||
| build: ## Build the release (compressed XZ file) | ||
| test "${DB_VERSION}" | ||
| ./sql/build.sh ${DB_VERSION} | ||
| du -h ${DB_XZ_FILE} | ||
|
|
||
| .PHONY: test | ||
| test: ## Test the SQL database with basic queries | ||
| test -f ${DB_FILE} | ||
| sqlite3 ${DB_FILE} ".tables" | ||
| sqlite3 ${DB_FILE} "\ | ||
| SELECT * FROM nutr_def WHERE id=328; \ | ||
| SELECT long_desc FROM food_des WHERE id=9050; \ | ||
| SELECT * FROM version; \ | ||
| " | ||
|
|
||
| .PHONY: docs | ||
| docs: ## Build the relational SVG diagram | ||
| ./docs/sqleton.sh | ||
|
|
||
|
|
||
|
|
||
| # --------------------------------------- | ||
| # Deploy | ||
| # --------------------------------------- | ||
|
|
||
| .PHONY: deploy/get-current-db-version | ||
| deploy/get-current-db-version: | ||
| @test "${DB_VERSION}" | ||
| @echo v${DB_VERSION} | ||
|
|
||
|
|
||
| .PHONY: deploy/upload | ||
| deploy/upload: ## Upload to GitHub releases | ||
| test -n "${DB_VERSION}" | ||
| test -f ${DB_XZ_FILE} | ||
| gh release create v${DB_VERSION} --generate-notes | ||
| gh release upload v${DB_VERSION} ${DB_XZ_FILE} | ||
|
|
||
| .PHONY: deploy/delete | ||
| deploy/delete: | ||
| [[ "$(shell read -e -p 'Really delete v${DB_VERSION}? [y/N]> '; echo $$REPLY)" == [Yy]* ]] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Interactive confirmation prompt won't work because Prompt for AI agents |
||
| gh release delete v${DB_VERSION} | ||
| git push origin --delete v${DB_VERSION} | ||
| - git tag -d v${DB_VERSION} | ||
|
|
||
|
|
||
|
|
||
| # --------------------------------------- | ||
| # Clean & extras | ||
| # --------------------------------------- | ||
|
|
||
| .PHONY: clean | ||
| clean: ## Clean up leftover bits and stuff from build | ||
| rm -f sql/*.sqlite | ||
| rm -f sql/*.sqlite3 | ||
|
|
||
| .PHONY: check-vars | ||
| check-vars: ## display all computed vars (won't show passed in) | ||
| $(foreach v, $(.VARIABLES), $(if $(filter file, $(origin $(v))), $(info $(v)=$($(v))))) | ||
|
|
||
| .PHONY: extras/cloc | ||
| extras/cloc: ## count lines of code | ||
| cloc HEAD --exclude-dir=usda.svg | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,9 @@ | ||||||||||||||||
| *********** | ||||||||||||||||
| ************* | ||||||||||||||||
| usda-sqlite | ||||||||||||||||
| *********** | ||||||||||||||||
| ************* | ||||||||||||||||
|
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The overline/underline around the document title use 13 asterisks while the title text is 12 characters, violating reStructuredText’s requirement that section adornments match the title length and causing Docutils warnings. Prompt for AI agents
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| .. image:: https://api.travis-ci.com/nutratech/usda-sqlite.svg?branch=master | ||||||||||||||||
| :target: https://travis-ci.com/github/nutratech/usda-sqlite | ||||||||||||||||
| .. image:: https://github.com/nutratech/usda-sqlite/actions/workflows/test.yml/badge.svg | ||||||||||||||||
| :target: https://github.com/nutratech/usda-sqlite/actions/workflows/test.yml | ||||||||||||||||
|
|
||||||||||||||||
| Python, SQL and CSV files for setting up portable usda-sqlite database. | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -12,6 +12,7 @@ See CLI: https://github.com/nutratech/cli | |||||||||||||||
| See nt-sqlite: https://github.com/nutratech/nt-sqlite | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| Building the database | ||||||||||||||||
| ######################### | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -30,7 +31,9 @@ Building the database | |||||||||||||||
| bash setup.sh | ||||||||||||||||
| python3 process.py | ||||||||||||||||
|
|
||||||||||||||||
| 3. If you are committing database changes, add a line to :code:`sql/version.csv` (e.g. :code:`id=3` is the latest in this case), | ||||||||||||||||
|
|
||||||||||||||||
| 3. If you are committing database changes, add a line to | ||||||||||||||||
| :code:`sql/version.csv` (e.g. :code:`id=3` is the latest in this case). | ||||||||||||||||
|
|
||||||||||||||||
| +-----+----------+-----------------------------------+ | ||||||||||||||||
| | id | version | created | | ||||||||||||||||
|
|
@@ -42,33 +45,36 @@ Building the database | |||||||||||||||
| | 3 | 0.0.2 | Thu 06 Aug 2020 09:21:39 AM EDT | | ||||||||||||||||
| +-----+----------+-----------------------------------+ | ||||||||||||||||
|
|
||||||||||||||||
| 4. i. (Optional) Enforce foreign keys with your ``~/.sqliterc`` file, | ||||||||||||||||
|
|
||||||||||||||||
| :: | ||||||||||||||||
| 4. i. *(Optional)* Enforce FKs by copying this to your ``~/.sqliterc`` file. | ||||||||||||||||
|
|
||||||||||||||||
| .. code-block:: text | ||||||||||||||||
|
|
||||||||||||||||
| .headers on | ||||||||||||||||
| .mode column | ||||||||||||||||
| PRAGMA foreign_keys = 1; | ||||||||||||||||
|
|
||||||||||||||||
| 4. ii. Create the database with | ||||||||||||||||
| 4. ii. Create the database. | ||||||||||||||||
|
|
||||||||||||||||
| .. code-block:: bash | ||||||||||||||||
|
|
||||||||||||||||
| cd ../sql | ||||||||||||||||
| ./build.sh X.X.X # e.g. 0.0.8 | ||||||||||||||||
| make build | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| 5. Verify the tables (again inside the SQL shell :code:`sqlite3 usda.sqlite3`), | ||||||||||||||||
| 5. Verify the tables. | ||||||||||||||||
|
|
||||||||||||||||
| .. code-block:: sql | ||||||||||||||||
|
|
||||||||||||||||
| .tables | ||||||||||||||||
| SELECT * FROM nutr_def WHERE id=328; | ||||||||||||||||
| SELECT long_desc FROM food_des WHERE id=9050; | ||||||||||||||||
| SELECT * FROM version; | ||||||||||||||||
| .exit | ||||||||||||||||
| make test | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| 6. If everything looks good, upload compressed | ||||||||||||||||
| :code:`dist/nutra-X.X.X.db.tar.xz` file to binary host. | ||||||||||||||||
|
|
||||||||||||||||
| .. code-block:: bash | ||||||||||||||||
|
|
||||||||||||||||
| make deploy/upload | ||||||||||||||||
|
|
||||||||||||||||
| 6. If everything looks good, upload compressed :code:`dist/nutra-X.X.X.db.tar.xz` file to binary host (bitbucket files). | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| Tables (Relational Design) | ||||||||||||||||
|
|
||||||||||||||||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Self-hosted runner with write permissions and broad branch triggers creates security risk. Consider: (1) restricting the trigger to specific branches like
main/masteronly, (2) using GitHub-hosted runners for untrusted branches, or (3) removing write permissions and using a separate workflow for deployments.Prompt for AI agents