Trigger GitLab Image Pipeline #295
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Trigger GitLab Image Pipeline | |
on: | |
schedule: | |
- cron: "00 11,15 * * *" | |
workflow_call: | |
workflow_dispatch: | |
workflow_run: | |
workflows: ["Store version artifacts"] | |
types: | |
- completed | |
jobs: | |
store-version: | |
uses: nextmcloud/.github/.github/workflows/nmc-store-version-artifacts.yml@nmc/2027-build-test-rtoth | |
trigger-build-pipeline: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Check the current time zone | |
run: echo date +'%:z %Z' | |
- name: Get Workflow run ID | |
id: get-workflow-run-id | |
run: | | |
# Fetch workflows | |
WORKFLOW_NAME="Store version artifacts" | |
WORKFLOW_RUN_ID=$(curl -s "https://api.github.com/repos/nextmcloud/.github/actions/runs" | jq -r --arg WORKFLOW_NAME "$WORKFLOW_NAME" '.workflow_runs[] | select(.name == $WORKFLOW_NAME) | .id') | |
echo "Workflow Run ID: $WORKFLOW_RUN_ID" | |
echo "::set-output name=workflow_run_id::$WORKFLOW_RUN_ID" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
WORKFLOW_RUN_ID: $WORKFLOW_RUN_ID | |
- name: Get Artifact ID | |
id: get-artifact-id | |
run: | | |
# Get the latest artifact ID | |
ARTIFACT_ID=$(curl -s "https://api.github.com/repos/nextmcloud/.github/actions/runs/$WORKFLOW_RUN_ID/artifacts" | jq -r '.artifacts[0].id') | |
echo "GitHub Actions workspace: ${{ github.workspace }}" | |
echo "Artifact ID: $ARTIFACT_ID" | |
echo "::set-output name=artifact_id::$ARTIFACT_ID" | |
# Construct Artifact URL | |
ARTIFACT_URL="https://api.github.com/repos/nextmcloud/.github/actions/artifacts/$ARTIFACT_ID" | |
echo "::set-output name=artifact_url::$ARTIFACT_URL" | |
echo "Artifact URL: $ARTIFACT_URL" | |
# Construct Download URL | |
set -x | |
DOWNLOAD_URL=$(curl -s "$ARTIFACT_URL" | jq -r '.archive_download_url') | |
set +x | |
echo "::set-output name=download_url::$DOWNLOAD_URL" | |
echo "Download URL: $DOWNLOAD_URL" | |
# Confirm File name | |
FILENAME=$(curl -LJO -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/nextmcloud/actions/runs/$WORKFLOW_RUN_ID/artifacts/$ARTIFACT_ID/zip" \ | |
-w '%{filename_effective}') | |
echo "::set-output name=filename::$FILENAME" | |
echo "File name is: $FILENAME" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
WORKFLOW_RUN_ID: ${{ steps.get-workflow-run-id.outputs.workflow_run_id }} | |
ARTIFACT_ID: $ARTIFACT_ID | |
ARTIFACT_URL: $ARTIFACT_URL | |
DOWNLOAD_URL: $DOWNLOAD_URL | |
FILENAME: $FILENAME | |
- name: Download and extract versions artifact | |
id: download-artifact | |
run: | | |
curl -LJO -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
"$DOWNLOAD_URL" | |
echo "Downloaded file: $FILENAME" | |
# List workspace contents | |
echo "List directory" | |
ls -a "${{ github.workspace }}" | |
# Extract artifact | |
unzip "${{ github.workspace }}/versions-combined.zip" | |
# CAT content | |
cat "${{ github.workspace }}/versions-combined.txt" | |
# Re-list workspace contents | |
echo "List directory" | |
ls -a "${{ github.workspace }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
WORKFLOW_RUN_ID: ${{ steps.get-workflow-run-id.outputs.workflow_run_id }} | |
ARTIFACT_ID: ${{ steps.get-artifact-id.outputs.artifact_id }} | |
ARTIFACT_URL: ${{ steps.get-artifact-id.outputs.artifact_url }} | |
DOWNLOAD_URL: ${{ steps.get-artifact-id.outputs.download_url }} | |
FILENAME: ${{ steps.get-artifact-id.outputs.filename }} | |
- name: Trigger Nmc deployment image building with versions | |
id: trigger-build | |
run: | | |
# Read artifact into variable | |
VERSIONS=$(cat "${{ github.workspace }}/versions-combined.txt") | |
echo "$VERSIONS" | |
# TEST *** Extract the value of PKR_VAR_NC_TAG from VERSIONS | |
#PKR_VAR_NC_TAG=$(echo "$VERSIONS" | grep "PKR_VAR_NC_TAG" | cut -d':' -f2 | sed 's/^[[:space:]]*"\(.*\)"/\1/' | tr -d '[:space:]') | |
PKR_VAR_NC_TAG=$(echo "$VERSIONS" | grep "PKR_VAR_NC_TAG" | cut -d':' -f2 | sed 's/^[^=]*=//' | tr -d '[:space:]') | |
echo "::set-output name=PKR_VAR_NC_TAG::$PKR_VAR_NC_TAG" | |
echo "PKR_VAR_NC_TAG: $PKR_VAR_NC_TAG" | |
# Read the source .gitlab-ci.yml content | |
#EXISTING_CONTENT=$(curl -H "PRIVATE-TOKEN: $PRIVATE_TOKEN" "$GITLAB_API/projects/$CI_PROJECT_ID/repository/files/$FILE_PATH/raw?ref=master") | |
# | |
#echo "EXISTING_CONTENT: $EXISTING_CONTENT" | |
# | |
## Perform substitution to update the value of PKR_VAR_NC_TAG | |
#NEW_CONTENT=$(echo "$EXISTING_CONTENT" | sed "s/PKR_VAR_NC_TAG: .*/PKR_VAR_NC_TAG: "$PKR_VAR_NC_TAG"/") | |
# | |
#echo "NEW_CONTENT: $NEW_CONTENT" | |
# | |
#URL_ENCODED_NEW_CONTENT=$(awk -v ORS='\\n' '1' "$NEW_CONTENT" ) | |
# | |
#echo "B64_NEW_CONTENT: $B64_NEW_CONTENT" | |
# | |
#echo "GITLAB_API: $GITLAB_API" | |
#echo "CI_PROJECT_ID: $CI_PROJECT_ID" | |
#echo -e "NEW_CONTENT: $NEW_CONTENT" # Use echo -e to interpret escape sequences | |
#echo "PRIVATE_TOKEN: $PRIVATE_TOKEN" | |
# | |
#curl -X PUT \ | |
# -H "PRIVATE-TOKEN: $PRIVATE_TOKEN" \ | |
# -H "Content-Type: application/json" \ | |
# -d '{"branch": "master", "content": "'"$B64_NEW_CONTENT"'", "commit_message": "Update .gitlab-ci.yml"}' \ | |
# "$GITLAB_API/projects/$CI_PROJECT_ID/repository/files/$FILE_PATH" | |
- name: Update CI File | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "rhtot" | |
git clone --depth 1 --branch master https://rhtot:[email protected]/nextmagentacloud/themes.git | |
cd "${{ github.workspace }}/themes" | |
sed -i 's|PKR_VAR_NC_TAG:.*|PKR_VAR_NC_TAG: '"$PKR_VAR_NC_TAG"'|g' .gitlab-ci.yml | |
cat .gitlab-ci.yml | |
git commit -am "Testing Update PKR_VAR_NC_TAG in .gitlab-ci.yml" | |
git push | |
env: | |
CI_PROJECT_ID: 21527 | |
GITLAB_API: https://gitlab.devops.telekom.de/api/v4 | |
FILE_PATH: .gitlab-ci.yml | |
PRIVATE_TOKEN: "${{ secrets.GITLAB_PIPELINE_TOKEN }}" | |
PKR_VAR_NC_TAG: "${{ steps.trigger-build.outputs.PKR_VAR_NC_TAG }}" | |