Re-use same yaml file in GitHub action

Hello,

I am trying to migrate a project was managed by GitLab on-prem with full CI/CD pipeline and repo to Github Ent on-prem

the build environment will be still the same and the delivery environment will be still the same

can I re-use same yaml file in GitHub action to speed up process of migrating current CI/CD pipeline

Thanks,
Yousef

Github Actions and Gitlab CI both use YAML files for configuration, but the expected structures are pretty different. So I’m afraid you’ll have to rewrite the workflow.

Side note: I’m not sure how far Actions is available for self-hosted servers yet, I saw the public roadmap lists a beta for this quarter.

thanks for the reply how far the structure is different for below example
https://docs.gitlab.com/ee/ci/examples/artifactory_and_gitlab/

image: maven:latest

variables:
  MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

cache:
  paths:
    - .m2/repository/
    - target/

build:
  stage: build
  script:
    - mvn $MAVEN_CLI_OPTS compile

test:
  stage: test
  script:
    - mvn $MAVEN_CLI_OPTS test

deploy:
  stage: deploy
  script:
    - mvn $MAVEN_CLI_OPTS deploy
  only:
    - master

Hi @yayh,

To use Github action for the sample, please try:

jobs:
  my_job:
    runs-on: ubuntu-latest
    container:
      image: maven         # use 'maven' container
      env:         # define env 
        MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
        MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
    steps:
      - name: checkout        # checkout repo content
        uses: actions/checkout@v2
      - name: cache       # cache the two directories, 'key' parameter is required by the action.
        uses: actions/cache@v2
        with:
          path: |
            ~/.m2/repository
            target
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
      - name: build
        run: |
          mvn $MAVEN_CLI_OPTS compile
      - name: test
        run: |
          mvn $MAVEN_CLI_OPTS test
      - name: deploy
        if: github.ref=='refs/heads/master'    # check if it's master branch, otherwise skip the step.
        run: |
          mvn $MAVEN_CLI_OPTS deploy

Please refer to below docs for the details:
https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontainer
https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows
https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsif

Thanks

1 Like