diff --git a/.github/workflows/check_derivatives_change.yml b/.github/workflows/check_derivatives_change.yml index 9dfc51c5..602550eb 100644 --- a/.github/workflows/check_derivatives_change.yml +++ b/.github/workflows/check_derivatives_change.yml @@ -16,6 +16,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} - name: Check if the PR changes any of the derivative databases id: changed-files @@ -27,13 +29,6 @@ jobs: !plane-alert-pia.csv !plane-alert-twitter-blocked.csv !plane-alert-ukraine.csv - separator: "," - - - name: List all changed files - run: | - for file in ${{ steps.changed-files.outputs.all_changed_files }}; do - echo "$file was changed" - done - uses: actions/setup-python@v4 if: steps.changed-files.outputs.any_changed == 'true' @@ -49,7 +44,7 @@ jobs: if: steps.changed-files.outputs.any_changed == 'true' id: invalid_derivatives env: - CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + PULL_REQUEST_NUMBER: ${{ github.event.number }} run: python ./scripts/check_invalid_derivatives.py - name: Store derivative check results as artifacts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c4709cc8..21eb5761 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ You can keep your fork, and thus your private Vercel instance up to date with th As the [README](README.md) explains, this repository uses GitHub actions to create several derivative databases from the main databases. By default, to prevent conflicts, the [create_db_derivatives.yaml](.github/workflows/create_db_derivatives.yaml) action is disabled on forks. You can, however, set the `CREATE_DERIVATIVES` repository variable to `true` in your repository settings (see [the GitHub documentation](https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-a-repository)) if you want to create the derivative database on your fork automatically. > **Warning** -> If you enable the building of the derivative databases on your fork, please use a feature branch (e.g. `patch`) when creating pull requests to the main repository. This will prevent your PR from being flagged as `invalid` since commits made by the [create_db_derivatives.yaml](.github/workflows/create_db_derivatives.yaml) do not re-trigger the PR check actions. You can then merge your changes into your main branch without waiting for the PR to be merged. If you really want to work from the `main` branch, this is also possible, but then you have to run the `create_db_derivatives.py` file on your local machine to get the correct derivative files included in the PR. +> If you enable the building of the derivative databases on your fork, please use a feature branch (e.g. `patch`) when creating pull requests to the main repository. This will prevent your PR from being flagged as `invalid` since commits made by the [create_db_derivatives.yaml](.github/workflows/create_db_derivatives.yaml) do not re-trigger the PR check actions. You can then merge your changes into your main branch without waiting for the PR to be merged. ## Report bugs using Github's [issues](https://github.com/sdr-enthusiasts/plane-alert-db/issues) diff --git a/scripts/check_invalid_derivatives.py b/scripts/check_invalid_derivatives.py index b9c655dc..40bac65f 100644 --- a/scripts/check_invalid_derivatives.py +++ b/scripts/check_invalid_derivatives.py @@ -11,7 +11,7 @@ format="%(asctime)s %(levelname)-8s [%(name)s] %(message)s", level=logging.INFO ) -CHANGED_FILES = os.environ["CHANGED_FILES"] +PULL_REQUEST_NUMBER = os.environ["PULL_REQUEST_NUMBER"] MAIN_DB_FILES = [ "plane-alert-db.csv", "plane-alert-pia.csv", @@ -24,7 +24,17 @@ if __name__ == "__main__": logging.info("Getting the PR files...") requests_session = requests.Session() - pr_files = CHANGED_FILES.split(",") + response = requests_session.get( + f"https://api.github.com/repos/sdr-enthusiasts/plane-alert-db/pulls/{PULL_REQUEST_NUMBER}/files" + ) + response.raise_for_status() + pr_files = response.json() + pr_files = [ + pr_file["filename"] + for pr_file in pr_files + if pr_file["filename"].endswith(".csv") + and pr_file["filename"] not in MAIN_DB_FILES + ] # Filter main database files and non CSV files. logging.info("PR files retrieved successfully.") logging.info("Getting changed files...")