LoveLH / Caddy_CustomBuild

Caddy定制化编译平台
MIT License
1 stars 0 forks source link

怎么在 github action里设置arm环境编译的 #20

Open crazypeace opened 1 year ago

crazypeace commented 1 year ago

你好. 想学习你是怎么在 github action里设置arm环境编译的 我查看了 workflows/custom.yml 没看出来哪里是设置不同的操作系统环境的。

请大佬指点。

github-actions[bot] commented 1 year ago

crazypeace 您好.
根据 title 和 body 内容的分析, 该 Issue 并非定制 Caddy. 将在管理员看到后会进行回复.

https://github.com/LoveLH/Caddy_CustomBuild/actions/runs/4394862158

LoveLH commented 1 year ago

您客气了,我算不上大佬的,我是抄的readme中提到的自动编译redpill的那个项目。 在custom.yml中,get issues info这个step中,是取issues中的body内容,set build info这个step中,使用python分析并设定了环境变量。如下:

      - name: Get Build Info
        shell: python
        run: |
          # -*- coding: utf-8 -*-
          import json, re, subprocess, requests
          def set_output(name, value): #设置环境变量用的函数
              subprocess.call(["echo '{}={}' >> $GITHUB_ENV".format(name, value)], shell=True) 
          if __name__ == '__main__':
              issues = 'false'
              iscustom = 'true'
              errinfo = ''
              warinfo = ''
              GOOS = ''
              GOARCH = ''
              GOARM = ''
              version = ''
              addons = ''
              try:
                  body = {}
                  bodyOriginal = {}
                  if '${{ github.event_name }}' == 'issues':
                      if '${{ env.issuetitle }}'.lower().startswith('custom'):
                          issues = 'true'
                          bodyOriginal = json.loads('${{ env.issuebody }}')
                      else:
                          iscustom = 'false'
                  else:
                      bodyOriginal = json.loads('${{ inputs.body }}')
                  for k, v in bodyOriginal.items():
                    body[k] = v
                  if len(body) == 0:
                      iscustom = 'false'
                      errinfo = 'body 错误, body is null'
                  else:
                      if 'GOOS' in body: GOOS = body['GOOS'].strip() #在body中拿到环境变量
                      if 'GOARCH' in body: GOARCH = body['GOARCH'].strip()
                      if 'GOARM' in body: GOARM = body['GOARM'].strip()
                      if 'version' in body: version = body['version'].strip()
                      if 'addons' in body: addons = body['addons'].strip()
              except Exception as e:
                  iscustom = 'false'
                  errinfo = 'body 错误, 不符合JSON规范 {}.'.format(e)

              if GOOS == '':
                GOOS = 'linux'
              if GOARCH == '':
                GOARCH = 'amd64'
              if 'arm' in GOARCH:
                if GOARM == '':
                  errinfo = '使用arm指令集需要指定arm架构版本。'
              if version == '':
                version = json.loads(requests.get('https://api.github.com/repos/caddyserver/caddy/releases/latest').text)['tag_name']
              if iscustom == 'true' and addons != '':
                  curAddons = [ x.strip() for x in re.split(',| |\|', addons) if x.strip() != '' ]
                  curAddons = list(set(curAddons))
                  if iscustom == 'true' and addons != '':
                    addons = ''
                    for cur in curAddons:
                      cur = '--with ' + cur + ' '
                      addons = addons + cur
              set_output('issues', issues)  #使用上面的设置环境变量的函数来设置环境变量
              set_output('iscustom', iscustom)
              set_output('errinfo', errinfo)
              set_output('warinfo', warinfo)
              set_output('GOOS', GOOS)
              set_output('GOARCH', GOARCH)
              set_output('version', version)
              set_output('GOARM', GOARM)
              set_output('addons', addons)
crazypeace commented 1 year ago

你好,我能看明白是把相关的字符串取出来放到了 GOARCH。 我的疑问是,这是个系统变量吗?这个一改,系统的架构就变了? 我没有看到使用 GOARCH 去设置 什么什么 的语句。

抱歉我对此非常小白,应该是门都没有入。如果您不想废话,建议我先去看某些 readme 或 文档,麻烦给个链接。 非常感谢!

LoveLH commented 9 months ago

不好意思,我好久没有注意这个项目了 具体的做法,你其实是可以参考caddy官方的文档的 Build from source 在这里有关于xcaddy的使用方式