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

Extract meta-repo code into meta-repo-content-push. #257

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/actions/meta-repo/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Push data to meta-repo

inputs:
META_CONTENT:
required: true
default: ''
description: Data to put into `metafile.txt`
META_REPO:
required: true
default: ''
description: Target meta repo to sync metadata changes
META_REPO_BRANCH:
required: true
default: ''
description: Target meta repo branch name
META_REPO_DEFAULT_BRANCH:
required: false
default: 'main'
description: Target meta repo default branch name

runs:
using: "composite"
steps:

- name: Encode '${{ inputs.META_REPO_BRANCH }}' and write to ENV
id: encode-meta-repo-branch
shell: bash
run: |
echo "META_REPO_BRANCH_B64=$(echo -n ${{ inputs.META_REPO_BRANCH }} | base64)" | tee -a "${GITHUB_ENV}"
echo "meta-repo-branch-b64=$(echo -n ${{ inputs.META_REPO_BRANCH }} | base64)" | tee -a "${GITHUB_OUTPUT}"

- name: Checkout metadata repo (${{ inputs.META_REPO_BRANCH }})
uses: actions/checkout@v4
id: meta-branch-exists
continue-on-error: true
with:
repository: ${{ inputs.META_REPO }}
ref: ${{ inputs.META_REPO_BRANCH }}
token: ${{ env.GH_BOT_DEPLOY_TOKEN || github.token }}
fetch-depth: 1
path: ${{ steps.encode-meta-repo-branch.outputs.meta-repo-branch-b64 }}

- name: Checkout metadata repo (${{ inputs.META_REPO_BRANCH }})
uses: actions/checkout@v4
if: steps.meta-branch-exists.outcome != 'success'
with:
repository: ${{ inputs.META_REPO }}
ref: ${{ inputs.META_REPO_DEFAULT_BRANCH }}
token: ${{ env.GH_BOT_DEPLOY_TOKEN || github.token }}
fetch-depth: 1
path: ${{ steps.encode-meta-repo-branch.outputs.meta-repo-branch-b64 }}
clean: true

- name: Create remote branch (${{ inputs.META_REPO_BRANCH }})
if: steps.meta-branch-exists.outcome != 'success'
shell: bash
working-directory: ${{ steps.encode-meta-repo-branch.outputs.meta-repo-branch-b64 }}
run: |
git checkout -b ${{ inputs.META_REPO_BRANCH }}
git push --set-upstream origin ${{ inputs.META_REPO_BRANCH }}

- name: Push changes
shell: bash
working-directory: ${{ steps.encode-meta-repo-branch.outputs.meta-repo-branch-b64 }}
run: |
git config --global user.email "[email protected]" && \
git config --global user.name "github-actions"

echo "${{ inputs.META_CONTENT }}" | tee metafile.txt

git status --porcelain | grep -q . || exit 0

git add -v metafile.txt && \
git commit --branch -m "update metadata" && \
git push --atomic -v
68 changes: 21 additions & 47 deletions .github/workflows/cicd-docker-build-and-distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ on:
default: ''
description: A prefix to append to meta file (also target folder where the files should be sent on remote)
META_REPO:
required: true
required: false
type: string
default: ''
description: Target meta repo to sync metadata changes
Expand Down Expand Up @@ -174,7 +174,11 @@ jobs:

meta-repo:
runs-on: ${{ inputs.RUNNER }}
if: ${{ inputs.UPLOAD_BUILD_ARTIFACTS }}
if: >-
${{
inputs.UPLOAD_BUILD_ARTIFACTS == 'true' &&
inputs.META_REPO != ''
}}
needs:
- build-and-distribute
permissions:
Expand All @@ -183,53 +187,23 @@ jobs:
environment: ${{ inputs.ENVIRONMENT }}
steps:

- name: Encode '${{ inputs.META_REPO_BRANCH }}' and write to ENV
id: encode-meta-repo-branch
shell: bash
run: |
echo "META_REPO_BRANCH_B64=$(echo -n ${{ inputs.META_REPO_BRANCH }} | base64)" | tee -a "${GITHUB_ENV}"
echo "meta-repo-branch-b64=$(echo -n ${{ inputs.META_REPO_BRANCH }} | base64)" | tee -a "${GITHUB_OUTPUT}"

- name: Checkout metadata repo (${{ inputs.META_REPO_BRANCH }})
- name: Checkout reusable actions
uses: actions/checkout@v4
id: meta-branch-exists
continue-on-error: true
with:
repository: ${{ inputs.META_REPO }}
ref: ${{ inputs.META_REPO_BRANCH }}
token: ${{ secrets.GH_BOT_DEPLOY_TOKEN || github.token }}
repository: signalwire/actions-template
ref: master
fetch-depth: 1
path: ${{ steps.encode-meta-repo-branch.outputs.meta-repo-branch-b64 }}
path: actions
sparse-checkout: |
.github/actions/meta-repo/action.yml
sparse-checkout-cone-mode: false

- name: Checkout metadata repo (${{ inputs.META_REPO_BRANCH }})
uses: actions/checkout@v4
if: steps.meta-branch-exists.outcome != 'success'
- name: Push build specific data to meta-repo
uses: ./actions/.github/actions/meta-repo
with:
repository: ${{ inputs.META_REPO }}
ref: ${{ inputs.META_REPO_DEFAULT_BRANCH }}
token: ${{ secrets.GH_BOT_DEPLOY_TOKEN || github.token }}
fetch-depth: 1
path: ${{ steps.encode-meta-repo-branch.outputs.meta-repo-branch-b64 }}
clean: true

- name: Create remote branch (${{ inputs.META_REPO_BRANCH }})
if: steps.meta-branch-exists.outcome != 'success'
working-directory: ${{ steps.encode-meta-repo-branch.outputs.meta-repo-branch-b64 }}
run: |
git checkout -b ${{ inputs.META_REPO_BRANCH }}
git push --set-upstream origin ${{ inputs.META_REPO_BRANCH }}

- name: Push changes
shell: bash
working-directory: ${{ steps.encode-meta-repo-branch.outputs.meta-repo-branch-b64 }}
run: |
git config --global user.email "[email protected]" && \
git config --global user.name "github-actions"

echo "${{ inputs.META_FILE_PATH_PREFIX }}" | tee metafile.txt

git status --porcelain | grep -q . || exit 0

git add -v metafile.txt && \
git commit --branch -m "update metadata" && \
git push --atomic -v
META_CONTENT: ${{ inputs.META_FILE_PATH_PREFIX }}
META_REPO: ${{ inputs.META_REPO }}
META_REPO_BRANCH: ${{ inputs.META_REPO_BRANCH }}
META_REPO_DEFAULT_BRANCH: ${{ inputs.META_REPO_DEFAULT_BRANCH }}
env:
GH_BOT_DEPLOY_TOKEN: ${{ secrets.GH_BOT_DEPLOY_TOKEN }}
68 changes: 68 additions & 0 deletions .github/workflows/meta-repo-content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Push data to meta-repo

on:
workflow_call:
inputs:
ENVIRONMENT:
required: false
type: string
description: Environment where the variables and secrets are scoped to
RUNNER:
required: false
default: ubuntu-latest
description: A GitHub runner type
type: string
META_CONTENT:
required: true
type: string
default: ''
description: Data to put into `metafile.txt`
META_REPO:
required: true
type: string
default: ''
description: Target meta repo to sync metadata changes
META_REPO_BRANCH:
required: true
type: string
default: ''
description: Target meta repo branch name
META_REPO_DEFAULT_BRANCH:
required: false
type: string
default: 'main'
description: Target meta repo default branch name

secrets:
GH_BOT_DEPLOY_TOKEN:
required: true

jobs:
meta-repo-content-push:
runs-on: ${{ inputs.RUNNER }}
permissions:
contents: read
id-token: write
environment: ${{ inputs.ENVIRONMENT }}
steps:

- name: Checkout reusable actions
uses: actions/checkout@v4
with:
repository: signalwire/actions-template
ref: master
fetch-depth: 1
path: actions
sparse-checkout: |
.github/actions/meta-repo/action.yml
sparse-checkout-cone-mode: false

- name: Push build specific data to meta-repo
uses: ./actions/.github/actions/meta-repo
with:
META_CONTENT: ${{ inputs.META_CONTENT }}
META_REPO: ${{ inputs.META_REPO }}
META_REPO_BRANCH: ${{ inputs.META_REPO_BRANCH }}
META_REPO_DEFAULT_BRANCH: ${{ inputs.META_REPO_DEFAULT_BRANCH }}
env:
GH_BOT_DEPLOY_TOKEN: ${{ secrets.GH_BOT_DEPLOY_TOKEN }}