From c43df87fc25ea79c3fb46c51a07d615ea80f05cf Mon Sep 17 00:00:00 2001 From: jasminabrar <73445895+jasminabrar@users.noreply.github.com> Date: Mon, 8 Jan 2024 07:41:39 -0800 Subject: [PATCH 1/4] upload merge files from artifact to permanent gh-pages link instead of updating read me --- .github/workflows/merge.yml | 85 +++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 26 deletions(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index f96a9f1b..7c4fa39f 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -28,7 +28,6 @@ jobs: - name: run merge script run: | - python merge/EBeam_merge.py - name: move merge output files to new folder @@ -44,47 +43,81 @@ jobs: cp "/home/runner/work/openEBL-2024-02/openEBL-2024-02/merge/$file" merge_output/ done - - name: upload artifact + - name: upload merge artifact uses: actions/upload-artifact@v4 id: artifact-upload with: name: merge-files path: merge_output/ - - name: get artifact url + - name: add vars needed for merge artifact url to a txt file run: | IFS='/' read -ra REPO <<< "$GITHUB_REPOSITORY" OWNER="${REPO[0]}" REPO_NAME="${REPO[1]}" - echo "Owner: $OWNER" - echo "Repository: $REPO_NAME" - RUN_ID=${{ github.run_id }} ARTIFACT_ID=${{ steps.artifact-upload.outputs.artifact-id }} - ARTIFACT_URL="https://github.com/$OWNER/$REPO_NAME/actions/runs/$RUN_ID/artifacts/$ARTIFACT_ID" - echo "Artifact URL: $ARTIFACT_URL" + + # add vars to txt file + echo "$ARTIFACT_ID" > url_info.txt + echo "$RUN_ID" >> url_info.txt + echo "$OWNER" >> url_info.txt + echo "$REPO_NAME" >> url_info.txt + + - name: upload txt file as an artifact + uses: actions/upload-artifact@v4 + with: + name: url-info + path: url_info.txt + + # seperate job needed so we can check out and change code from gh-pages branch + update-url: + runs-on: ubuntu-latest + + needs: merge + + steps: + - name: checkout repo content + uses: actions/checkout@v2 + with: + ref: gh-pages + + - name: download url-info artifact + uses: actions/download-artifact@v4 + with: + name: url-info + path: . - echo "ARTIFACT_URL=$ARTIFACT_URL" >> $GITHUB_ENV + - name: get vars from url_info.txt file + run: | + ARTIFACT_ID=$(head -1 url_info.txt) + RUN_ID=$(sed -n '2p' url_info.txt) + OWNER=$(sed -n '3p' url_info.txt) + REPO_NAME=$(sed -n '4p' url_info.txt) + + echo "ARTIFACT_ID=$ARTIFACT_ID" >> $GITHUB_ENV + echo "RUN_ID=$RUN_ID" >> $GITHUB_ENV echo "OWNER=$OWNER" >> $GITHUB_ENV + echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV + + - name: delete url-info artifact + uses: geekyeggo/delete-artifact@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + name: url-info - - name: update url in runner README + - name: update index.html with new merge artifact link run: | - start_delim="" - end_delim="" - - # remove current URL - sed -i "/$start_delim/,/$end_delim/d" README.md - - # add new URL - printf "$start_delim\n$ARTIFACT_URL\n$end_delim\n" >> README.md - - # merge script always runs on any PR, this ensures link is only updated after a PR is merged into SiEPIC - - name: commit and push changes to README if we are in SiEPIC repo + echo "New artifact URL: https://github.com/$OWNER/$REPO_NAME/actions/runs/$RUN_ID/artifacts/$ARTIFACT_ID" + sed -i 's|URL=https://github.com/'"$OWNER"'/'"$REPO_NAME"'/actions/runs/.*|URL=https://github.com/'"$OWNER"'/'"$REPO_NAME"'/actions/runs/'"$RUN_ID"'/artifacts/'"$ARTIFACT_ID"'">|' index.html + sed -i 's|href="https://github.com/'"$OWNER"'/'"$REPO_NAME"'/actions/runs/.*|href="https://github.com/'"$OWNER"'/'"$REPO_NAME"'/actions/runs/'"$RUN_ID"'/artifacts/'"$ARTIFACT_ID"'">|' index.html + + # merge script always runs on any PR, the if statement ensures link is only updated after a PR is merged into SiEPIC + - name: push changes to gh-pages branch run: | - git diff - git config --local user.email "${{ github.actor }}@users.noreply.github.com" - git config --local user.name "${{ github.actor }}" - git add README.md - git commit -m "update README with new artifact url $ARTIFACT_URL" + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor }}@users.noreply.github.com" + git add index.html + git commit -m "Update index.html to redirect to new merge artifact url" git push if: ${{ env.OWNER == 'SiEPIC'}} From b3f83a5779c95460e33a80275b87f31c69999a16 Mon Sep 17 00:00:00 2001 From: jasminabrar <73445895+jasminabrar@users.noreply.github.com> Date: Mon, 8 Jan 2024 07:56:21 -0800 Subject: [PATCH 2/4] only download python-to-oas-gds artifact if triggered on workflow run --- .github/workflows/run-verification.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-verification.yml b/.github/workflows/run-verification.yml index 23bbfd71..4872b9ba 100644 --- a/.github/workflows/run-verification.yml +++ b/.github/workflows/run-verification.yml @@ -44,6 +44,7 @@ jobs: name: python-to-oas-gds path: ./binary_files search_artifacts: true + if: ${{ github.event_name == 'workflow_run' }} - name: get .gds and .oas files run: | From 1dfe2e23256806412864eccbffdc11e4efc01367 Mon Sep 17 00:00:00 2001 From: jasminabrar <73445895+jasminabrar@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:03:35 -0800 Subject: [PATCH 3/4] remove brackets around FILES --- .github/workflows/run-verification.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-verification.yml b/.github/workflows/run-verification.yml index 4872b9ba..4e4404a3 100644 --- a/.github/workflows/run-verification.yml +++ b/.github/workflows/run-verification.yml @@ -75,7 +75,7 @@ jobs: IFS=$'\n' # run verification on all files - for file in "$FILES"; do + for file in $FILES; do echo "Running verification on $file" From ee2ab761264a2c95ecdb541f1e1fada77542ad52 Mon Sep 17 00:00:00 2001 From: jasminabrar <73445895+jasminabrar@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:33:28 -0800 Subject: [PATCH 4/4] change from env.OWNER to github.repository_owner --- .github/workflows/merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 7c4fa39f..2db3d6b5 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -120,4 +120,4 @@ jobs: git add index.html git commit -m "Update index.html to redirect to new merge artifact url" git push - if: ${{ env.OWNER == 'SiEPIC'}} + if: ${{ github.repository_owner == 'SiEPIC'}}