{"id":13837830,"url":"https://github.com/TomasHubelbauer/github-actions","last_synced_at":"2025-07-10T19:30:51.195Z","repository":{"id":107986117,"uuid":"224903129","full_name":"TomasHubelbauer/github-actions","owner":"TomasHubelbauer","description":"Infromation and tips regarding GitHub Actions","archived":false,"fork":false,"pushed_at":"2022-04-14T20:20:18.000Z","size":121,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-02T03:54:57.019Z","etag":null,"topics":["cd","ci","ci-cd","github","github-actions"],"latest_commit_sha":null,"homepage":"","language":"Markdown","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TomasHubelbauer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-29T18:18:10.000Z","updated_at":"2024-08-04T15:49:10.744Z","dependencies_parsed_at":null,"dependency_job_id":"179f4c3f-e0c1-4191-a019-9922db59bd72","html_url":"https://github.com/TomasHubelbauer/github-actions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasHubelbauer%2Fgithub-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasHubelbauer%2Fgithub-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasHubelbauer%2Fgithub-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasHubelbauer%2Fgithub-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TomasHubelbauer","download_url":"https://codeload.github.com/TomasHubelbauer/github-actions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225653891,"owners_count":17502939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cd","ci","ci-cd","github","github-actions"],"created_at":"2024-08-04T15:01:27.576Z","updated_at":"2024-11-21T00:31:15.047Z","avatar_url":"https://github.com/TomasHubelbauer.png","language":"Markdown","readme":"# GitHub Actions\n\n[**WEB**](https://tomashubelbauer.github.io/github-actions)\n\n## Status Badge\n\nSee [github-actions-badge](https://github.com/TomasHubelbauer/github-actions-badge)\nfor GitHub Actions workflow status image badge MarkDown link syntax.\n\n## Workflow File Location\n\n`.github/workflows/$name.yml` - the `$name` can be whatever you like.\n\n## Manual Runs\n\nhttps://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow\n\n## Read Workflow\n\nThis workflow script proceeds to validate the repository without pushing any\nartifacts to it.\n\n```yml\nname: main\non: push\n\njobs:\n  main:\n    runs-on: ubuntu-latest\n    steps:\n    - name: Check out the main branch\n      uses: actions/checkout@v3\n      with:\n        ref: main\n\n    - name: Run the workflow\n      run: |\n        # Print shell commands as they execute\n        set -x\n        \n        # Run the script\n        node .\n```\n\n## Write Workflow\n\n**Note:** Writing back to the repository is also possible with REST (sole file)\nand GraphQL (multiple files). Prefer this for new integrations!\n\nhttps://github.com/TomasHubelbauer/github-actions-push-api\n\nThis workflow scripts executes a command and then commits its outputs to the\nrepository associated with the workflow.\n\n```yml\nname: main\non: push\n\njobs:\n  main:\n    runs-on: ubuntu-latest\n    steps:\n    - name: Check out the main branch\n      uses: actions/checkout@v3\n      with:\n        ref: main\n\n    - name: Run the workflow\n      run: |\n        # Fail on error\n        set -e\n        \n        # Print shell commands as they execute\n        set -x\n        \n        # Configure Git for the push from the workflow to the repository\n        # These credentials will make the commit associate with the GitHub Actions service account\n        git config --global user.email \"41898282+github-actions[bot]@users.noreply.github.com\"\n        git config --global user.name \"github-actions[bot]\"\n        \n        # Run the script\n        node .\n        \n        # Stage the Git index changes resulting from the CI script\n        git add *\n        \n        # Reset unstaged changes so that Git commit won't fail (e.g.: package-lock.json, temporary files, …)\n        git checkout -- .\n        \n        # Bail if there are no changes to commit and hence no GitHub Pages to build\n        if git diff-index --quiet HEAD --; then\n          exit\n        fi\n        \n        # Commit the staged changes to the workflow repository\n        git commit -m \"Commit generated content\"\n        \n        # Rebase if the branch has changed meanwhile or fail on automatically irresolvable conflicts\n        git pull --rebase\n        \n        # Push the commit to the workflow repository\n        # This will not cause an infinite loop, GitHub knows it is from the agent and will not run the workflow again\n        git push\n```\n\nAn alternative way to do this is to buy in to the proprietary GitHub Actions\nsyntax and get the benefit of the nicer UI. I would only do this for simple\nscripts that are easy to convert back to Bash with just copy-paste if needed.\n\n```yml\nname: main\non:\n  push:\n  schedule:\n    - cron: \"0 0 * * *\"\n\njobs:\n  main:\n    runs-on: ubuntu-latest\n    steps:\n      # We need to check out first so that we have a baseline to make a diff of\n      - name: Check out the main branch\n        uses: actions/checkout@v3\n        with:\n          ref: main\n\n      # Set up Git identity before making any changes\n      - name: Commit and push the change to the GitHub repository from the agent\n        run: |\n          # Configure Git for the push from the workflow to the repository\n          # (This is needed even with the workflow PAT)\n          # These credentials will make the commit associate with the GitHub Actions service account\n          git config --global user.email \"41898282+github-actions[bot]@users.noreply.github.com\"\n          git config --global user.name \"github-actions[bot]\"\n\n      # Carry out the workflow work\n      - name: Run the workflow script or do some other stuff in more steps\n        run: node .\n\n      - name: Stage the changes resulting from the above steps\n        run: git add *\n\n      - name: Bail if there are no changes staged to commit\n        id: bail\n        continue-on-error: true\n        run: |\n          git status\n          if git diff-index --quiet HEAD --; then\n            echo \"::set-output name=bail::true\"\n          else\n            echo \"::set-output name=bail::false\"\n          fi\n\n      - name: Commit the staged changes to the workflow repository\n        if: ${{steps.bail.outputs.bail == 'false'}}\n        run: git commit -m \"Capture workflow changes\"\n\n      - name: Rebase if the branch has changed meanwhile or fail on conflicts\n        if: ${{steps.bail.outputs.bail == 'false'}}\n        run: git pull --rebase\n\n      - name: Push the commit to the workflow repository\n        if: ${{steps.bail.outputs.bail == 'false'}}\n        run: git push\n```\n\n## GitHub Pages Deployment Workflow\n\nThis GitHub Actions workflow builds on top of the write one above. GitHub Pages\ncan be hosted either from the root of the repository or the `docs` folder, so the\nabove workflow needs to be updated to write the contents the GitHub Pages should\nhave to the right directory first.\n\nIt requires a custom PAT to invoke the GitHub API and deploy the GitHub Pages,\nbecause the integration PAT doesn't cause GitHub Pages to build on push and using\nthe custom PAT to push would cause an infinite GitHub Actions chain on the push.\n\nIn case of CRA, it is imporant to set the `homepage` field of the CRA `package.json`\nso that the built site has correct relative URLs since it is going to be hosted on\na path relative to the GitHub Pages domain unless a custom domain is configured.\n\n```yml\n        … the workflow script so far …\n\n        # Enqueue and monitor a GitHub Pages deployment using the GitHub API and the custom PAT\n        # (The out-of-the-box PAT is an integration PAT - not privileged to make GitHub Pages API calls)\n        \n        # Authorize using the custom PAT which is privileged to call the GitHub Pages API\n        authorization=\"Authorization: token ${{secrets.GITHUB_PAGES_PAT}}\"\n        \n        pagesBuildsUrl=\"https://api.github.com/repos/${{github.repository}}/pages/builds\"\n        pagesBuildsJson=\"pages-builds.json\"\n\n        curl -s -f -X POST -H \"$authorization\" $pagesBuildsUrl \u003e $pagesBuildsJson\n        status=$(jq '.status' $pagesBuildsJson | tr -d '\"')\n        echo $status\n        if [ \"$status\" != \"queued\" ]\n        then\n          exit 1\n        fi\n\n        pagesBuildsLatestUrl=$(jq '.url' $pagesBuildsJson | tr -d '\"')\n        pagesBuildsLatestJson=\"pages-builds-latest.json\"\n\n        rm $pagesBuildsJson\n        while true\n        do\n          sleep 5\n          curl -s -f -H \"$authorization\" $pagesBuildsLatestUrl \u003e $pagesBuildsLatestJson\n          status=$(jq '.status' $pagesBuildsLatestJson | tr -d '\"')\n          echo $status\n          if [ \"$status\" = \"built\" ]\n          then\n            rm $pagesBuildsLatestJson\n            exit\n          fi\n        done\n```\n\n## Scheduled Runs\n\nAdd this to make the workflow run daily:\n\n```yml\non:\n  push:\n  schedule:\n    - cron: \"0 0 * * *\"\n```\n\nChange to this to limit to the main branch:\n\n```yml\non:\n  push:\n    branches:\n    - main\n  schedule:\n    # Run daily\n    - cron:  '0 0 * * *'\n```\n\n\n**Scheduled runs do not have access to the cache.**\n\n## Email Notifications\n\nThere is no built in way to send email notifications from the workflow runs.\nOne has to code that up themselves. I've wrapped the implementation in a repo:\n\n**To be able to clone the repo, one has to use a custom PAT, since it is private.**\n\n```yml\n# Send myself an email\ngit clone https://TomasHubelbauer:${{secrets.GITHUB_ACTIONS_PAT}}@github.com/TomasHubelbauer/self-email.git\nchmod +x ./self-email/self-email.sh\necho \"Hi.\" \u003e\u003e email.eml\ncat email.eml | ./self-email/self-email.sh\n```\n\n## Cache\n\nIt is possible to cache things across workflow runs:\n\nChange the Cron to `0 * * * *` to run hourly.\n\nhttps://help.github.com/en/actions/automating-your-workflow-with-github-actions/caching-dependencies-to-speed-up-workflows\n\nHowever, scheduled runs do not have access to the cache.\n\n## Notes\n\nUnlike Azure Pipelines at which GitHub Actions are based on, the `steps` object\nis required in GitHub Actions and cannot be skipped to go straight to the step.\n\n## To-Do\n\n### Learn about artifacts and demonstrate them\n\nhttps://help.github.com/en/actions/automating-your-workflow-with-github-actions/persisting-workflow-data-using-artifacts\n\n### Go through the docs and document interesting features\n\n### Replace the Write Workflow section with a link to the experimental repo\n\nhttps://github.com/TomasHubelbauer/github-actions-push-api\n\nAll of the new write workflows should be based on this and the old ones changed\nto this.\n\n### Validate whether the integration PAT token with Actions identity emits Pages\n\nI am not sure what change, but I think Pages either get deployed on commits from\nthe workflow in general, or maybe only when using the integration PAT or maybe\neven when impersonating the Actions service account (with the integration PAT?).\n","funding_links":[],"categories":["Markdown"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTomasHubelbauer%2Fgithub-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTomasHubelbauer%2Fgithub-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTomasHubelbauer%2Fgithub-actions/lists"}