sinoTrinity
sinoTrinity

Reputation: 1195

Can GitHub Actions create a release to a public repo from a private repo?

I want to create a release that contains assets for users to download. Since it is a private repo, I want to create the release in a separate public repo. Is this doable in GitHub Actions?

There are owner and repo parameters in create-release action, but I kept getting errors after setting them to a different repo:

   - name: Create Release
     id: create_release
     uses: actions/create-release@v1
     env:
       GITHUB_TOKEN: ${{ secrets.PAT }} # A personal access token
     with:
       tag_name: ${{ github.ref }}
       release_name: Release ${{ github.ref }}
       draft: false
       prerelease: false
       owner: foo
       repo: another_public_repo

Error: Validation Failed: {"resource":"Release","code":"custom","field":"tag_name","message":"tag_name is not a valid tag"}, {"resource":"Release","code":"custom","message":"Published releases must have a valid tag"}, {"resource":"Release","code":"invalid","field":"target_commitish"}

Upvotes: 6

Views: 3425

Answers (1)

riQQ
riQQ

Reputation: 12693

You either have to specify an existing tag in tag_name. In your case that means creating the tag in the public repository before creating the release. Or you can specify a branch or commit SHA in commitish, which is used if the tag specified in tag_name doesn't exist.

  - name: Checkout public repository
    uses: actions/checkout@v2
    with:
      repository: foo/another_public_repo
      path: another_public_repo
  - name: Get tag name from ref
    shell: bash
    run: echo "{tag}={${GITHUB_REF#refs/tags/}}" >> $GITHUB_OUTPUT
    id: get_tag
  - name: Create tag in public repository
    run: |
      cd ${{github.workspace}}/another_public_repo
      git tag ${{ steps.get_tag.outputs.tag }}
      git push --tags --porcelain
  - name: Create Release
    id: create_release
    uses: actions/create-release@v1
    env:
      GITHUB_TOKEN: ${{ secrets.PAT }} # A personal access token
    with:
      tag_name: ${{ steps.get_tag.outputs.tag }}
      release_name: Release ${{ steps.get_tag.outputs.tag }}
      draft: false
      prerelease: false
      owner: foo
      repo: another_public_repo

Upvotes: 1

Related Questions