FunkinCrew / funkinBounties

EZ WORK I WANT DONE FOR CHEAP LOL!
30 stars 1 forks source link

100$ - Github Actions / Haxe / HaxeFlixel - Caching HaxeFlixel output stuff in Github Actions #3

Closed ninjamuffin99 closed 8 months ago

ninjamuffin99 commented 1 year ago

Introductory Information

Github Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production.

github.com/actions/cache

For Friday Night Funkin' we use Github Actions to compile and build the game for testing purposes. Ideally we want to run it every push, on every branch. However Github Actions has a limitation in private repos, where you only get a certain amount of MINUTES, thus the need to find ways to save time in compiles.

One way to save such time is to save certain libraries and output files in the Github Actions cache, using https://github.com/actions/cache

The Project

Save Github Actions minutes compiling a HaxeFlixel project for Windows, Mac, Linux, and HTML5 using Github Actions Caching to cache certain crazy lil output files, as well as caching haxelibs.

Create a Github Action that can easily work for any and all HaxeFlixel based projects to properly cache any file needed, that works alongside the HMM dependency manager

Prerequisites

Github Actions knowhow, which pretty much entails decent cute little command line knowhow. Github Actions has free minutes for public repos, so shouldn't be a problem for you to test out teehee

Okay-ish know how of how Haxeflixel / OpenFL / Lime projects compile, how haxelibs work, etc.

How Much Can ninjamuffin Help?

Budget/Timeline

My dipshit estimate is that this can probably be done in a short afternoon or so. I just am too lazy lol! I really mean it when I say it seems straightforward! Currently have 70$ 100$ USD allocated, but can prob toss you bit more if it takes longer than an hour or two.

No rush or timeline on this though, it's a pretty quality of life feature!

AltronMaxX commented 1 year ago

Something like this?

YoshiCrafter29 commented 1 year ago

Implemented this feature in Codename 2 months ago

Brings down compilation times to:

Note that compilation times take less than a minute (or more depending on the amount of changes), the rest is used by cache sync up and artifact upload. Rarely, invalid caches can also cause compilation time to go back up to 30-60 minutes, but only happens once since the cache is automatically replaced.

ninjamuffin99 commented 1 year ago

hmmm i tried implementing it, but the github-script part of it got busted.

the error it spits out to me is this

RequestError [HttpError]: Resource not accessible by integration
    at C:\a\_actions\actions\github-script\v6\dist\index.js:6803:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async eval (eval at callAsyncFunction (C:\a\_actions\actions\github-script\v6\dist\index.js:15099:16), <anonymous>:3:16)
    at async main (C:\a\_actions\actions\github-script\v6\dist\index.js:15198:20) {
  status: 403,
  response: {
    url: 'https://api.github.com/repos/FunkinCrew/Funkin-secret/actions/caches',
    status: 403,
    headers: {
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
      connection: 'close',
      'content-encoding': 'gzip',
      'content-security-policy': "default-src 'none'",
      'content-type': 'application/json; charset=utf-8',
Error: Unhandled error: HttpError: Resource not accessible by integration
      date: 'Thu, 09 Mar 2023 01:42:43 GMT',
      'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
      server: 'GitHub.com',
      'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
      'transfer-encoding': 'chunked',
      vary: 'Accept-Encoding, Accept, X-Requested-With',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'deny',
      'x-github-api-version-selected': '2022-11-28',
      'x-github-media-type': 'github.v3',
      'x-github-request-id': '0400:8BF8:42401E3:8802E99:64093993',
      'x-ratelimit-limit': '1000',
      'x-ratelimit-remaining': '999',
      'x-ratelimit-reset': '1678329763',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '1',
      'x-xss-protection': '0'
    },
    data: {
      message: 'Resource not accessible by integration',
      documentation_url: 'https://docs.github.com/rest/actions/cache#list-github-actions-caches-for-a-repository'
    }
  },
  request: {
    method: 'GET',
    url: 'https://api.github.com/repos/FunkinCrew/Funkin-secret/actions/caches',
    headers: {
      accept: 'application/vnd.github.-preview+json',
      'user-agent': 'actions/github-script octokit-core.js/3.6.0 Node.js/16.16.0 (win32; x64)',
      authorization: 'token [REDACTED]'
    },
    request: { agent: [Agent], hook: [Function: bound bound register] }
  }
}
AltronMaxX commented 1 year ago

Try to add this code inside every job.

permissions:
       contents: write
       actions: write

It should be placed like in this part of workflow

jobs:
  buildWindows:
    # The type of runner that the job will run on
    runs-on: windows-latest

    permissions:
       contents: write
       actions: write

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@main
polybiusproxy commented 1 year ago

@ninjamuffin99 It's failing because you're doing this on a private repo.

And as the Octokit docs state:

You must authenticate using an access token with the repo scope to use this endpoint.

So, to pull this off, you would need to create a PAT (Personal Access Token) and add it as a secret in your repo (it's in the settings). Give it a name (let's say you gave it FUNKIN_PAT as a name), and give it the permissions it needs.

P.D.: Create a classic token, not a fine-grained one. Those are in beta, so I don't recommend using them yet. Here's a link, if you want to avoid the hassle of going thru the settings.

Now that you've got your PAT set up, you can now use it on your YAML like this:

github-token: ${{ secrets.FUNKIN_PAT }}

This is how you would use it:

- uses: actions/github-script@v6
        with:
          github-token: ${{ secrets.FUNKIN_PAT }}
          script: |
            const caches = await github.rest.actions.getActionsCacheList({
            ...

Could you keep me updated if it doesn't work? Cheers!

ninjamuffin99 commented 1 year ago

I will poke around right now @polybiusproxy !

ninjamuffin99 commented 8 months ago

closed, as i believe we just got this done internally !