diff --git a/.github/shared-actions/build-and-publish-docker/action.yaml b/.github/shared-actions/build-and-publish-docker/action.yaml new file mode 100644 index 0000000..d8a8b9b --- /dev/null +++ b/.github/shared-actions/build-and-publish-docker/action.yaml @@ -0,0 +1,42 @@ +name: Build and publish docker +description: This action should Build a docker image and publish to docker hub +inputs: + short_sha: + description: 'Git commit SHA' + required: true + build_image_script: + description: 'The shell script that builds the docker image' + required: true + default: ./ci/build-and-publish-image.sh + npm_token: + description: 'Npm Token' + required: true + docker_hub_password: + description: 'Docker Hub Password' + required: true + docker_hub_user: + description: 'Docker Hub User' + required: true + + + +runs: + using: "composite" + steps: + - name: Display Current Tag/SHA + run: echo Tag/SHA ${{ inputs.short_sha }} + shell: bash + - name: Build and push docker image + run: | + echo commit hash: ${COMMIT_HASH} + echo tag: ${TAG_NAME} + echo branch: ${BRANCH_NAME} + sudo chmod +x ${{ inputs.build_image_script }} + ${{ inputs.build_image_script }} + shell: bash + env: + COMMIT_HASH: ${{ inputs.short_sha }} + TAG_NAME: ${{ github.ref_name }} + NPM_TOKEN: ${{ inputs.npm_token }} + DOCKER_HUB_USER: ${{ inputs.docker_hub_user }} + DOCKER_HUB_PASSWORD: ${{ inputs.docker_hub_password }} diff --git a/.github/workflows/api-test.yaml b/.github/workflows/api-test.yaml new file mode 100644 index 0000000..9261810 --- /dev/null +++ b/.github/workflows/api-test.yaml @@ -0,0 +1,59 @@ +name: API tests job + +on: + workflow_call: + inputs: + build_image_script: + required: false + default: ./ci/build-and-publish-image.sh + type: string + secrets: + npm_token: + description: 'Npm Token' + required: true + docker_hub_password: + description: 'Docker Hub Password' + required: true + docker_hub_user: + description: 'Docker Hub User' + required: true + + +jobs: + params: + name: Prepare Parmas + runs-on: ubuntu-latest + outputs: + short_sha: ${{ steps.short-sha.outputs.short_sha }} + steps: + - name: Parse short sha + id: short-sha + run: | + if [ -z "${{ inputs.tag }}" ] + then + echo "::set-output name=short_sha::${GITHUB_SHA::7}" + else + echo "::set-output name=short_sha::$(${{ inputs.tag }})" + fi + + build-and-publish-docker: + name: Build and publish docker image + runs-on: ubuntu-latest + needs: [ params ] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Checkout workflows + uses: actions/checkout@v3 + with: + repository: frontegg/workflows + path: workflows + - name: build and publish docker image + uses: ./workflows/.github/shared-actions/build-and-publish-docker + with: + short_sha: ${{ needs.params.outputs.short_sha }} + build_image_script: ${{ inputs.build_image_script }} + npm_token: ${{secrets.npm_token}} + docker_hub_user: ${{ secrets.docker_hub_user }} + docker_hub_password: ${{ secrets.docker_hub_password }} + diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 5627f06..4eb9582 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -70,27 +70,26 @@ jobs: build-and-publish-docker: name: Build and publish docker image runs-on: ubuntu-latest - needs: [params] + needs: [ params ] steps: + - name: Checkout + uses: actions/checkout@v3 - name: Display Current Tag/SHA run: echo Tag/SHA ${{ needs.params.outputs.short_sha }} shell: bash - - name: Checkout + - name: Checkout workflows uses: actions/checkout@v3 - - name: Build and push docker image - run: | - echo commit hash: ${COMMIT_HASH} - echo tag: ${TAG_NAME} - echo branch: ${BRANCH_NAME} - sudo chmod +x ${{ inputs.build_image_script }} - ${{ inputs.build_image_script }} - shell: bash - env: - COMMIT_HASH: ${{ needs.params.outputs.short_sha }} - NPM_TOKEN: ${{ secrets.npm_token }} - TAG_NAME: ${{ github.ref_name }} - DOCKER_HUB_USER: ${{ secrets.docker_hub_user }} - DOCKER_HUB_PASSWORD: ${{ secrets.docker_hub_password }} + with: + repository: frontegg/workflows + path: workflows + - name: build and publish docker image + uses: ./workflows/.github/shared-actions/build-and-publish-docker + with: + short_sha: ${{ needs.params.outputs.short_sha }} + build_image_script: ${{ inputs.build_image_script }} + npm_token: ${{secrets.npm_token}} + docker_hub_user: ${{ secrets.docker_hub_user }} + docker_hub_password: ${{ secrets.docker_hub_password }} build-and-publish-hybrid-docker: name: Build and publish hybrid docker image