Giter Site home page Giter Site logo

test-upstream-github's Introduction

test-upstream-github

A sample project that uses Github Actions CI/CD to automatically push commits from a Github repository to GitLab. This method requires maintainer priviledges in both the Github and Gitlab repositories.

Instructions

  1. Create a Gitlab access token with write_repository access permissions. Copy the key.
  2. In your GitHub project, go to settings->secrets and add the key that you copied as a secret. Name it something like: GITLAB_PUSH_KEY
  3. Now, go to Gitlab and create a new repository. You can either create a new repository or clone your Github repo. In this example, I am using https://github.com/ckhordiasma/test-upstream-github/ and https://code.il2.dsop.io/chkodama/test-upstream-github
  4. Next, go back to Github and create the YML file. You can either do this by going to the 'Actions' section and starting a blank action, or you can make a blank file gitlab.yml and put it at /.github/workflows/gitlab.yml, making the folder structrure if it's not already there. Here's what you want in the contents of the file:
name: Push to GitLab CI

on: [push]

jobs:
  build:
    env:
      BRANCH: master
      DEST_BRANCH: github
      GITLAB_REPO: 'https://code.il2.dsop.io/chkodama/test-upstream-github.git'
      GITLAB_KEY: ${{ secrets.GITLAB_PUSH_KEY }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with: 
          ref: "${{ env.BRANCH }}"
          fetch-depth: 0
      - name: prep and push mirror
        run: |
          echo 'echo ${{ env.GITLAB_KEY }}' > ./creds.sh
          chmod 770 ./creds.sh
          git config --global credential.helper cache
          git config --global core.askPass ./creds.sh
          git remote add mirror "${{ env.GITLAB_REPO }}"
          git push --force -u mirror "${{ env.BRANCH }}":"${{ env.DEST_BRANCH }}"
  1. You will need to edit the values corresponding to BRANCH, DEST_BRANCH, and GITLAB_REPO to the correct values for you. In this example, I'm taking the 'master' branch from github and pushing changes from it into the 'github' branch in Gitlab. (You will also need to rename secrets.GITLAB_PUSH_KEY if you named the secret key something else).

  2. Commit changes and it should work (hopefully)! In this example I'm pushing to the 'github' branch in gitlab, and my workflow would be to manually merge into (gitlab's) master from there. If you wanted it to push directly into gitlab's master (maybe not recommended though), just configure it above to go to master on both ends.

test-upstream-github's People

Contributors

ckhordiasma avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.