Changes for page Create Automatically Updating Repo in GitHub
Last modified by chrisby on 2025/04/22 14:54
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,84 +1,38 @@ 1 + 1 1 ### GitHub Actions 2 2 3 3 The GitHub actions are used for CI purposes. One job is auto update, which can be enabled as follows: 4 - 5 5 * Repo > Settings > 6 - 7 - 8 - 9 - 10 - 11 - 12 - 6 + * General > 7 + * Pull Requests > enable "Allow auto-merge". 8 + * Branches > Add classic branch protection rule 9 + * Branch name pattern: main 10 + * Enable "Require status checks to pass before merging". 11 + * Actions > General > Workflow permissions > enable "Allow GitHub Actions to create and approve pull requests" 12 + * If option is greyed out, then probably the project policy is dictated by the repository policy. Simply do this in repository settings then. 13 13 * Copy the workflow file from this project. The key configs are the "permissions" to include "contents: write, pull-requests: write" and the "auto-merge" step. 14 14 15 15 If you don't need a private module from the same repository, you must delete the "Authenticate for private modules" job. Otherwise, the following steps are necessary: 16 - 17 17 * GitHub > Profile > Settings > Developer Settings > Personal Access Tokens > Tokens (classic) > Generate new token 18 - 19 - 20 - 17 + * Name: ACTIONS_TOKEN 18 + * Select scopes: "repo" 19 + * Copy the token 21 21 * Repo > Settings > Secrets and variables > Actions > New repository secret > 22 - 23 - 24 - 25 - 26 - 21 + * Name: MY_TOKEN 22 + * You need to set "environment: MY_TOKEN" in the workflow file to use its environment secrets 23 + * Environment Secrets > Add environment secret 24 + * Name: ACTIONS_TOKEN 25 + * Value: <the token you copied before> 27 27 28 28 Add this to the workflow file: 29 29 30 - - name: Authenticate for private modules 31 - env: 32 - ACTIONS_TOKEN: ${{ secrets.ACTIONS_TOKEN }} 33 - run: | 34 - git config --global url."https://${ACTIONS_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/" 35 - go env -w GOPRIVATE=github.com/ocelot-cloud/* 36 - 37 -This is a sample file how the weekly updates can be conducted via GitHub Actions. Create `.github/workflows/weekly-update.yml`: 38 - 39 -```none 40 -name: Weekly Update 41 - 42 -on: 43 - schedule: 44 - - cron: '0 2 * * 3' 45 - workflow_dispatch: 46 - 47 -permissions: 48 - contents: write 49 - pull-requests: write 50 - 51 -jobs: 52 - weekly-update: 53 - runs-on: ubuntu-latest 54 - steps: 55 - - uses: actions/checkout@v4 56 - 57 - - uses: ./.github/actions/setup 58 - 59 - - name: Run ci-runner update 29 +```yaml 30 + - name: Authenticate for private modules 31 + env: 32 + ACTIONS_TOKEN: ${{ secrets.ACTIONS_TOKEN }} 60 60 run: | 61 - go get -u ./... 62 - go mod tidy 63 - go build 64 - # execute the test suite to check whether the updates did not break anything 65 - 66 - - name: Commit and create PR 67 - id: cpr 68 - uses: peter-evans/create-pull-request@v5 69 - with: 70 - commit-message: "chore: weekly ci-runner update" 71 - branch: weekly/ci-update 72 - title: "Weekly CI Runner Update" 73 - delete-branch: true 74 - token: ${{ secrets.GITHUB_TOKEN }} 75 - 76 - - name: Enable Auto-Merge 77 - if: steps.cpr.outputs.pull-request-operation == 'created' 78 - uses: peter-evans/enable-pull-request-automerge@v3 79 - with: 80 - pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} 81 - merge-method: squash 34 + git config --global url."https://${ACTIONS_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/" 35 + go env -w GOPRIVATE=github.com/ocelot-cloud/* 82 82 ``` 83 83 84 84 ### Private Go Repository Dependency ... ... @@ -85,5 +85,7 @@ 85 85 86 86 If you are developing with Go and need a private repository as a dependency, you need to tell the SDK to use SSH instead of HTTPS to get access. 87 87 88 - git config --global url."ssh://git@github.com/".insteadOf "https://github.com/" 89 - go env -w GOPRIVATE=github.com/ocelot-cloud/* 42 +```bash 43 +git config --global url."ssh://git@github.com/".insteadOf "https://github.com/" 44 +go env -w GOPRIVATE=github.com/ocelot-cloud/* 45 +```