Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: pull from main - push to otherbranch? #63

Closed
Stwissel opened this issue Oct 3, 2020 · 5 comments
Closed

Question: pull from main - push to otherbranch? #63

Stwissel opened this issue Oct 3, 2020 · 5 comments
Labels
type: not a bug Reports that happen not be our fault

Comments

@Stwissel
Copy link

Stwissel commented Oct 3, 2020

Use case:
I have a front-end (Angular/React) and a backend repository. When the CI is building the front-end, the result of the build folder needs to be committed to the /static directory of the backend repo. With your contribution I came close - love it.
The last hurdle is the error:

** Error: warning: Pulling without specifying how to reconcile divergent branches is discouraged **

which AFAIK stems from the fact that I checkout master from backend and try to push to (the non-existing) branch ui-contribution. Is there a way I can push to a new (or eventually existing) branch. -u --force might do the trick, but where to put in in the YAML. My stuff so far:

name: Reconcile front and backend

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  buildui:
    name: Building UI
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Backend
        uses: actions/checkout@v2
        with:
          repository: acme/backend
          token: ${{secrets.UI_PUSH_TOKEN }}
          ref: main
          path: backend
      - name: Checkout UI
        uses: actions/checkout@v2
      - name: Deploy NodeJS
        uses: actions/setup-node@v1
        with:
          node-version: "12.x"
      - run: npm install
      - run: npm run build --if present
      - run: npm test
      - name: Send them back
        uses: EndBug/add-and-commit@v5
        with:
          cwd: "./backend"
          branch: "ui-commit"
          message: "[Auto-commit] from UI"
        env:
          GITHUB_TOKEN: ${{secrets.UI_PUSH_TOKEN }}

Love your work!

@EndBug EndBug added the status: pending More info is needed before deciding what to do label Oct 3, 2020
@EndBug
Copy link
Owner

EndBug commented Oct 3, 2020

Hi, thanks for reaching out! Could you send me a link to your workflow run so that I can look at the logs?

@Stwissel
Copy link
Author

Stwissel commented Oct 4, 2020

It's a private repo, I'll attach the raw log here:
rawlog.txt

@EndBug
Copy link
Owner

EndBug commented Oct 4, 2020

It seems that these logs don't match the workflow you posted, are you sure they're the right ones? I see different step names and that it's downloading the action from your fork

@Stwissel
Copy link
Author

Stwissel commented Oct 6, 2020

Ciao Frederico,
me dispiace, my team has cleaned out the log, that was the last one I could grab. I forked it, since I though I could change a little but that didn't work out. I isolated the issue and it seems a fundamental behaviour of git when you have subdirectories containing their own .git files.
Something the API might not allow us to address. Long story short: even if your working directory contains its own .git directory, the github actions API seems to treat any call against it as call towards the repository where the action was triggered from. So your code isn't the issue here.

I poked around and the only option that seems to work is to rely on a shell script and native git calls. As an added complication the target directory needs to be added as git module. Since the main repo is never pushed back, that's fine.

This is the script I finally used:

#!/bin/bash
# Send UI back to a new branch in backend
now=$(date +"%Y-%m-%d_%H-%M")
message="[UI Commit] ${now}"
# Step1 clone backend
git submodule add https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/$REPO2 backend
# Step3 update UI 
rm -rf backend/static/ui
mkdir -p backend/static/ui
cp build/* backend/static/ui/
cd backend
git config user.email "automation@acme.com"
git config user.name "Acme automation"
git add --all
git commit -m "$message"
git checkout -b ui/ui-$now
git push -u origin ui/ui-$now

Nice lesson learned: I originally used $GITHUB_REPO as environment variable instead of $REPO2, but that one is hard wired to the current repo - took me an hour (or longer) to figure that.

Anyway - we can close that issue. And mille grazie for your willingness to help out. Very much appreciated

@Stwissel Stwissel closed this as completed Oct 6, 2020
@EndBug EndBug added type: not a bug Reports that happen not be our fault and removed status: pending More info is needed before deciding what to do labels Oct 6, 2020
@EndBug
Copy link
Owner

EndBug commented Oct 6, 2020

Happy to hear that you managed to find a solution! This kind of issues can be hard to resolve since you're dealing with something that happens in a machine to which you don't have access, and I must confess that there's still some stuff I'm not really sure about GitHub Action runners 😅
Feel free to open other issues if you have any problem
Ciao ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: not a bug Reports that happen not be our fault
Projects
None yet
Development

No branches or pull requests

2 participants