0

I'm new to Github Action and Workflow.

My repository is a private one, and I want to host Github Page from that repository. So I build my app bundle and cd on it, initiating a new repository whose remote origin is same as the original one(Actually this is a recommended way to deploy on Github Page). I tried to make an orphan branch(gh-pages) and pushed it, resulting in the following error:

fatal: could not read Username for 'https://github.com/': No such device or address

Here is a total Github workflow yaml below:

name: Build and Deploy on Github Page
on:
  push:
    branches:
      - main
  workflow_dispatch:
permissions:
  contents: write
jobs:
  setup-build-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout to ${{ github.ref }} branch ️
        uses: actions/checkout@v3
        with:
          ref: ${{ env.BRANCH }}
      
      - name: Setup Node.js 
        uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Generate .env ⚙️
        run: |
          echo "_PAGE_TITLE=\"${{ vars._PAGE_TITLE }}\"" >> .env
          echo "_PAGE_DESCRIPTION=\"${{ vars._PAGE_DESCRIPTION }}\"" >> .env
          echo "_PAGE_URL=\"${{ vars._PAGE_URL }}\"" >> .env
          echo "_REPO_NAME=\"${{ vars._REPO_NAME }}\"" >> .env
      
      - name: Install app 
        run: yarn install # yarn install

      - name: Setup Git Identity 
        run: |
          git config --global user.name "GitHub Actions Bot"
          git config --global user.email "<>"
          # git config --global credential.helper cache # works same whether or not
      
      - name: Build and Deploy 
        run: sh gh-deploy.sh
# gh-deploy.sh
#!/usr/bin/env sh

# https://vitejs.dev/guide/static-deploy.html
set -e

yarn build

cd dist

echo > .nojekyll

git init
git checkout -B main
git add -A
git commit -m 'github page deploy'

# same as the repository which started the github action
git remote add origin https://github.com/cadenzah/xxxxx.git

git push -f origin main:gh-pages

cd ..
rm -rf dist

I wonder what is wrong with my configuration. Is it the issue with credential(PAT)?

EDIT: Isn't there any way to share the original credentials from actions/checkout on other directory(in which additional git(hub) repository is)?

cadenzah
  • 928
  • 3
  • 10
  • 23
  • Why are you creating a new repo with git unit? You can just reuse the directory from the check action ${{ GitHub.workspace }}, switch to the correct branch and the commit and push. Authentication is then handle by the special GITHUB_TOKEN that is automatically generated during the workflow run and has write access to your repo. – Rob Bos Jan 28 '23 at 18:42
  • @RobBos What I want(and maybe the guide from Vite intended) is to make a clean git repository and an orphan branch(`gh-pages`) to push, so that the `gh-pages` branch always have a single commit and there are only built bundle and assets files on `gh-pages` excluding the source files. That can't be achieved with sharing and reusing the directory I think. – cadenzah Jan 28 '23 at 18:59
  • 1
    In that case, you need to tell git how to authenticate with the remote. Since you are using https you can update that url to include a username (can be anything) and then the GITHUB_TOKEN as a password, to that the authentication can be used from there. – Rob Bos Jan 28 '23 at 19:02
  • Does this answer your question? [How to commit and push to a private repo(A), from a different repo(B), in github actions workflow (B) , using personal access token](https://stackoverflow.com/questions/70225077/how-to-commit-and-push-to-a-private-repoa-from-a-different-repob-in-github) – Azeem Jan 29 '23 at 08:31
  • Another alternative with deploy key: https://stackoverflow.com/a/70283191/7670262 – Azeem Jan 29 '23 at 08:32
  • @Azeem Thanks for your suggestion, but the links you provided solve the issue by adding Repository secrets, so those are not the solutions that I wanted, because I wanted to solve my issue without any additional variables or secrets. I figured out how to address my issue, so I will self-answer later. – cadenzah Jan 29 '23 at 14:51

0 Answers0