forgejo-runner

git clone git://git.lin.moe/forgejo-runner.git

  1# SPDX-License-Identifier: MIT
  2#
  3# https://code.forgejo.org/forgejo/runner
  4#
  5#  Build the runner binaries and OCI images
  6#
  7#  ROLE: forgejo-integration
  8#  DOER: forgejo-ci
  9#  TOKEN: <generated from https://code.forgejo.org/forgejo-ci>
 10#
 11name: Build release
 12
 13on:
 14  push:
 15    tags: 'v*'
 16
 17jobs:
 18  release:
 19    runs-on: self-hosted
 20    # root is used for testing, allow it
 21    if: secrets.ROLE == 'forgejo-integration' || github.repository_owner == 'root'
 22    steps:
 23      - uses: actions/checkout@v3
 24
 25      - name: Increase the verbosity when there are no secrets
 26        id: verbose
 27        run: |
 28          if test -z "${{ secrets.TOKEN }}"; then
 29            value=true
 30          else
 31            value=false
 32          fi
 33          echo "value=$value" >> "$GITHUB_OUTPUT"
 34
 35      - name: Sanitize the name of the repository
 36        id: repository
 37        run: |
 38          echo "value=${GITHUB_REPOSITORY##*/}" >> "$GITHUB_OUTPUT"
 39
 40      - name: create test TOKEN
 41        id: token
 42        if: ${{ secrets.TOKEN == '' }}
 43        run: |
 44          apt-get -qq install -y jq
 45          url="${{ env.GITHUB_SERVER_URL }}"
 46          hostport=${url##http*://}
 47          hostport=${hostport%%/}
 48          doer=root
 49          api=http://$doer:admin1234@$hostport/api/v1/users/$doer/tokens
 50          curl -sS -X DELETE $api/release
 51          token=$(curl -sS -X POST -H 'Content-Type: application/json' --data-raw '{"name": "release", "scopes": ["all"]}' $api | jq --raw-output .sha1)
 52          echo "value=${token}" >> "$GITHUB_OUTPUT"
 53
 54      - name: version from ref_name
 55        id: tag-version
 56        run: |
 57          version=${GITHUB_REF_NAME##*v}
 58          echo "value=$version" >> "$GITHUB_OUTPUT"
 59
 60      - name: release notes
 61        id: release-notes
 62        run: |
 63          anchor=${{ steps.tag-version.outputs.value }}
 64          anchor=${anchor//./-}
 65          cat >> "$GITHUB_OUTPUT" <<EOF
 66          value<<ENDVAR
 67          See https://code.forgejo.org/forgejo/runner/src/branch/main/RELEASE-NOTES.md#$anchor
 68          ENDVAR
 69          EOF
 70
 71      - name: build without TOKEN
 72        if: ${{ secrets.TOKEN == '' }}
 73        uses: https://code.forgejo.org/forgejo/forgejo-build-publish/build@v5
 74        with:
 75          forgejo: "${{ env.GITHUB_SERVER_URL }}"
 76          owner: "${{ env.GITHUB_REPOSITORY_OWNER }}"
 77          repository: "${{ steps.repository.outputs.value }}"
 78          doer: root
 79          sha: "${{ github.sha }}"
 80          release-version: "${{ steps.tag-version.outputs.value }}"
 81          token: ${{ steps.token.outputs.value }}
 82          platforms: linux/amd64,linux/arm64
 83          release-notes: "${{ steps.release-notes.outputs.value }}"
 84          binary-name: forgejo-runner
 85          binary-path: /bin/forgejo-runner
 86          verbose: ${{ steps.verbose.outputs.value }}
 87
 88      - name: build with TOKEN
 89        if: ${{ secrets.TOKEN != '' }}
 90        uses: https://code.forgejo.org/forgejo/forgejo-build-publish/build@v5
 91        with:
 92          forgejo: "${{ env.GITHUB_SERVER_URL }}"
 93          owner: "${{ env.GITHUB_REPOSITORY_OWNER }}"
 94          repository: "${{ steps.repository.outputs.value }}"
 95          doer: "${{ secrets.DOER }}"
 96          sha: "${{ github.sha }}"
 97          release-version: "${{ steps.tag-version.outputs.value }}"
 98          token: "${{ secrets.TOKEN }}"
 99          platforms: linux/amd64,linux/arm64
100          release-notes: "${{ steps.release-notes.outputs.value }}"
101          binary-name: forgejo-runner
102          binary-path: /bin/forgejo-runner
103          verbose: ${{ steps.verbose.outputs.value }}