Coder Social home page Coder Social logo

nathanvaughn / actions-cloudflare-purge Goto Github PK

View Code? Open in Web Editor NEW
30.0 30.0 8.0 587 KB

A GitHub Action to purge Cloudflare's cache of your site

License: MIT License

Dockerfile 0.54% Python 99.46%
cache-control cloudflare cloudflare-api github-actions

actions-cloudflare-purge's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar imgbotapp avatar nathanvaughn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

actions-cloudflare-purge's Issues

urllib.error.HTTPError: HTTP Error 400: Bad Request

Not sure what's going on here but I can't seem to get this action to work. I have the zone id for the site set properly and the API token has cache purge permissions for the zone. Every time I run the action it fails with the error urllib.error.HTTPError: HTTP Error 400: Bad Request during my build process for my blog.

Actions Log

Run nathanvaughn/***-cloudflare-purge@master
  with:
    cf_zone: ***
    cf_auth: ***
    hosts: ***
/usr/bin/docker run --name e547a168fcf780a4a47bfafa27737a14dea_a60823 --label 675e54 --workdir /github/workspace --rm -e "INPUT_CF_ZONE" -e "INPUT_CF_AUTH" -e "INPUT_HOSTS" -e "INPUT_URLS" -e "INPUT_FILES" -e "INPUT_TAGS" -e "INPUT_PREFIXES" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_ENVIRONMENT" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e "ACTIONS_RESULTS_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/blog/blog":"/github/workspace" 675e54:7a168fcf780a4a47bfafa27737a14dea  "--cf-zone=***" "--cf-auth=***" "--urls" "" "--files" "" "--tags" "" "--hosts" "***" "--prefixes" ""
Traceback (most recent call last):
  File "/app/main.py", line 149, in <module>
    main()
  File "/app/main.py", line 134, in main
Request:
https://api.cloudflare.com/client/v4/zones/***/purge_cache
Headers:
{
    "Authorization": "***",
    "Content-Type": "application/json",
    "User-Agent": "github.com/nathanvaughn/***-cloudflare-purge"
}
Payload:
{
    "hosts": [
        "***"
    ]
}
    resp = request.urlopen(req)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/urllib/request.py", line 215, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/urllib/request.py", line 521, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/urllib/request.py", line 630, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/urllib/request.py", line 559, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/urllib/request.py", line 492, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/urllib/request.py", line 639, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

Actions file

      - name: Purge Cloudflare Cache
        if: (steps.deploy.outcome  == 'success')
        uses: nathanvaughn/actions-cloudflare-purge@master
        with:
          cf_zone: ${{ secrets.CLOUDFLARE_ZONE_DEV }}
          cf_auth: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          hosts: ${{ secrets.DEVURL_NOHTTPS }}

Secret Setup
This is an example of how my secrets are setup to show I only have them and no extra data present.. redacted of course
CLOUDFLARE_ZONE_DEV = xxxxxxxxxxxxxxxxxxxxxxxxxx6e95
CLOUDFLARE_API_TOKEN = xxxxxxxxxxxxxxxxxxxxxxxxxx236x
DEVURL_NOHTTPS = blog.mydomain.com

Does not work if Cloudflare token starts with "-"

I'm customizing env vars as follows:


      - name: Cloudflare Cache Purge
        uses: nathanvaughn/actions-cloudflare-purge@master
        with:
            cf_zone: ${{ secrets.CLOUDFLARE_ZONE_ID }}
            cf_auth: ${{ secrets.CLOUDFLARE_API_TOKEN }}

My token contains a "-" as its first character and in the GitHub Action output I'm seeing that python tries to interpret the value as an -option:

Run nathanvaughn/actions-cloudflare-purge@master
  with:
    cf_zone: ***
    cf_auth: ***
  env:
    CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE: /home/runner/work/blog/blog/gha-creds-851f5[2](https://github.com/ahmetb/blog/actions/runs/3797304137/jobs/6458111224#step:8:2)[3](https://github.com/ahmetb/blog/actions/runs/3797304137/jobs/6458111224#step:8:3)[4](https://github.com/ahmetb/blog/actions/runs/3797304137/jobs/6458111224#step:8:4)[5](https://github.com/ahmetb/blog/actions/runs/3797304137/jobs/6458111224#step:8:5)41a0be5.json
    GOOGLE_APPLICATION_CREDENTIALS: /home/runner/work/blog/blog/gha-creds-851f5234541a0be5.json
    GOOGLE_GHA_CREDS_PATH: /home/runner/work/blog/blog/gha-creds-851f5234541a0be5.json
    CLOUDSDK_CORE_PROJECT: ahmetb-blog
    CLOUDSDK_PROJECT: ahmetb-blog
    GCLOUD_PROJECT: ahmetb-blog
    GCP_PROJECT: ahmetb-blog
    GOOGLE_CLOUD_PROJECT: ahmetb-blog
/usr/bin/docker run --name d20985be[6](https://github.com/ahmetb/blog/actions/runs/3797304137/jobs/6458111224#step:8:6)9494c5db[7](https://github.com/ahmetb/blog/actions/runs/3797304137/jobs/6458111224#step:8:7)5c30e0fdd57[8](https://github.com/ahmetb/blog/actions/runs/3797304137/jobs/6458111224#step:8:8)71_d[9](https://github.com/ahmetb/blog/actions/runs/3797304137/jobs/6458111224#step:8:9)f750 --label 290506 --workdir /github/workspace --rm -e "CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE" -e "GOOGLE_APPLICATION_CREDENTIALS" -e "GOOGLE_GHA_CREDS_PATH" -e "CLOUDSDK_CORE_PROJECT" -e "CLOUDSDK_PROJECT" -e "GCLOUD_PROJECT" -e "GCP_PROJECT" -e "GOOGLE_CLOUD_PROJECT" -e "INPUT_CF_ZONE" -e "INPUT_CF_AUTH" -e "INPUT_URLS" -e "INPUT_FILES" -e "INPUT_TAGS" -e "INPUT_HOSTS" -e "INPUT_PREFIXES" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e "ACTIONS_ID_TOKEN_REQUEST_URL" -e "ACTIONS_ID_TOKEN_REQUEST_TOKEN" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/blog/blog":"/github/workspace" 290506:d20985be69494c5db75c30e0fdd57871  "--cf-zone" "***" "--cf-auth" "***" "--urls" "" "--files" "" "--tags" "" "--hosts" "" "--prefixes" ""
usage: main.py [-h] [--cf-zone [CF_ZONE]] [--cf-auth [CF_AUTH]]
               [--urls [URLS ...]] [--files [FILES ...]] [--tags [TAGS ...]]
               [--hosts [HOSTS ...]] [--prefixes [PREFIXES ...]]
main.py: error: unrecognized arguments: ***

`files` must be an array

RE: using urls (internally files). Currently, it fails since it's passing through a string with space-delimited URLs with the following response:

{
    "success": false,
    "errors": [
        {
            "code": 1014,
            "message": "\"files\", \"tags\", \"hosts\" or \"prefixes\" must be an array"
        }
    ],
    "messages": [],
    "result": null
}

I'm not familiar with python, but if you could split the provided URL by (space), it should work as expected for us. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.