From 8ffa9117c124e0f0a45b3dc1150acf985a495cc4 Mon Sep 17 00:00:00 2001 From: Gichan Jang Date: Thu, 7 Nov 2024 18:31:19 +0900 Subject: [PATCH] [Action] Add composite action for duplicated works - use composite action for git push. - use composite action for s3 upload. Signed-off-by: Gichan Jang --- .github/actions/gitpush/action.yml | 40 +++++++++++++ .github/actions/s3_upload/action.yml | 34 +++++++++++ .github/workflows/publish_docs.yml | 33 +++++------ .github/workflows/update_gbs_cache.yml | 64 +++++++++++---------- .github/workflows/update_pbuilder_cache.yml | 16 +++--- 5 files changed, 130 insertions(+), 57 deletions(-) create mode 100644 .github/actions/gitpush/action.yml create mode 100644 .github/actions/s3_upload/action.yml diff --git a/.github/actions/gitpush/action.yml b/.github/actions/gitpush/action.yml new file mode 100644 index 0000000000..fb5c05a047 --- /dev/null +++ b/.github/actions/gitpush/action.yml @@ -0,0 +1,40 @@ +name: 'Push to github.io' +description: 'Update the github action result to nnstreamer.github.io' +inputs: + source: + description: 'source path of the file or directory to be copied' + required: true + dest: + description: 'destination directory in nnstreamer.github.io repository' + required: true + message: + description: 'commit message' + required: false + default: 'Update the result from nnstreamer github action.' + taos_account: + required: true + taos_account_token: + required: true + +runs: + using: "composite" + steps: + - name: update the result + run: | + git clone https://${{ inputs.taos_account }}:${{ inputs.taos_account_token }}@github.com/nnstreamer/nnstreamer.github.io.git + pushd nnstreamer.github.io + mkdir -p ${{ inputs.dest }} + cp -r ${{ inputs.source }} ${{ inputs.dest }} + git diff > git_diff.txt + DIFF_SIZE=$(stat -c%s git_diff.txt) + if [[ $DIFF_SIZE -ne 0 ]]; then + git config user.email "nnsuite@samsung.com" + git config user.name "nnsuite" + git add * + git commit -s -m "${{ inputs.message }}" + git push origin main -f + else + echo "Nothing to commit. Skip the push operation." + fi + popd + shell: bash diff --git a/.github/actions/s3_upload/action.yml b/.github/actions/s3_upload/action.yml new file mode 100644 index 0000000000..81d112f2e3 --- /dev/null +++ b/.github/actions/s3_upload/action.yml @@ -0,0 +1,34 @@ +name: 'upload to release.nnstreamer.com' +inputs: + source: + description: 'source path of the file or directory to be copied' + required: true + dest: + description: 'destination directory in release.nnstreamer.com repository' + required: true + s3_id: + required: true + s3_key: + required: true + s3_option: + required: false + default: "" + +runs: + using: "composite" + steps: + - name: get date + id: get-date + run: | + echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + shell: bash + + - name: update the result to s3 + env: + AWS_ACCESS_KEY_ID: ${{ inputs.s3_id }} + AWS_SECRET_ACCESS_KEY: ${{ inputs.s3_key }} + AWS_EC2_METADATA_DISABLED: true + run: | + aws s3 cp --region ap-northeast-2 ${{ inputs.source }} s3://nnstreamer-release/nnstreamer/${{ steps.get-date.outputs.date }}/${{ inputs.dest }} ${{ inputs.s3_option }} + aws s3 cp --region ap-northeast-2 ${{ inputs.source }} s3://nnstreamer-release/nnstreamer/latest/${{ inputs.dest }} ${{ inputs.s3_option }} + shell: bash diff --git a/.github/workflows/publish_docs.yml b/.github/workflows/publish_docs.yml index 0645d144ff..4c0920bb27 100644 --- a/.github/workflows/publish_docs.yml +++ b/.github/workflows/publish_docs.yml @@ -31,16 +31,13 @@ jobs: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - name: Update github.io - run: | - git clone https://${{ secrets.TAOS_ACCOUNT }}:${{ secrets.TAOS_ACCOUNT_TOKEN }}@github.com/nnstreamer/nnstreamer.github.io.git - cp -r Documentation/NNStreamer-doc/html/* nnstreamer.github.io/ - pushd nnstreamer.github.io - git config user.email "nnsuite@samsung.com" - git config user.name "nnsuite" - git add * - git commit -s -m "${{ steps.get-date.outputs.date }} : Update nnstreamer.github.io" - git push origin main -f - popd + uses: ./.github/actions/gitpush + with: + source: ${{ github.workspace }}/Documentation/NNStreamer-doc/html/* + dest: ./ + message: "${{ steps.get-date.outputs.date }} : Update nnstreamer.github.io." + taos_account: ${{ secrets.TAOS_ACCOUNT }} + taos_account_token: ${{ secrets.TAOS_ACCOUNT_TOKEN }} generate_doxybook: # reference: https://github.com/nnstreamer/TAOS-CI/tree/main/ci/doxybook @@ -60,11 +57,11 @@ jobs: id: get-date run: | echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - - name: Release daily build result - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} - AWS_EC2_METADATA_DISABLED: true - run: | - aws s3 cp --region ap-northeast-2 latex/nnstreamer-book.pdf s3://nnstreamer-release/nnstreamer/${{ steps.get-date.outputs.date }}/doc/nnstreamer-book.pdf - aws s3 cp --region ap-northeast-2 latex/nnstreamer-book.pdf s3://nnstreamer-release/nnstreamer/latest/doc/nnstreamer-book.pdf + + - name: Release daily build result to release.nnstreamer.com + uses: ./.github/actions/s3_upload + with: + source: ${{ github.workspace }}/latex/nnstreamer-book.pdf + dest: doc/nnstreamer-book.pdf + s3_id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} + s3_key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/update_gbs_cache.yml b/.github/workflows/update_gbs_cache.yml index 7704e33c18..b8e427dc97 100644 --- a/.github/workflows/update_gbs_cache.yml +++ b/.github/workflows/update_gbs_cache.yml @@ -63,16 +63,22 @@ jobs: path: ~/GBS-ROOT/local/cache key: gbs-cache-${{ matrix.gbs_build_arch }}-${{ steps.get-date.outputs.date }} - - name: Release daily build result - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} - AWS_EC2_METADATA_DISABLED: true - run: | - aws s3 cp --recursive --region ap-northeast-2 ~/GBS-ROOT/local/repos/tizen/${{ matrix.gbs_build_arch }}/RPMS/ s3://nnstreamer-release/nnstreamer/${{ steps.get-date.outputs.date }}/RPMS/ - aws s3 cp --recursive --region ap-northeast-2 ~/GBS-ROOT/local/repos/tizen/${{ matrix.gbs_build_arch }}/RPMS/ s3://nnstreamer-release/nnstreamer/latest/RPMS/ - aws s3 cp --region ap-northeast-2 ~/GBS-ROOT/local/repos/tizen/${{ matrix.gbs_build_arch }}/logs/*/*/log.txt s3://nnstreamer-release/nnstreamer/${{ steps.get-date.outputs.date }}/logs/tizen_gbs_${{ matrix.gbs_build_arch }}_log.txt - aws s3 cp --region ap-northeast-2 ~/GBS-ROOT/local/repos/tizen/${{ matrix.gbs_build_arch }}/logs/*/*/log.txt s3://nnstreamer-release/nnstreamer/latest/logs/tizen_gbs_${{ matrix.gbs_build_arch }}_log.txt + - name: Release daily build result to release.nnstreamer.com + uses: ./.github/actions/s3_upload + with: + source: ~/GBS-ROOT/local/repos/tizen/${{ matrix.gbs_build_arch }}/RPMS/ + dest: RPMS/ + s3_id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} + s3_key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} + s3_option: --recursive + + - name: Release daily build log to release.nnstreamer.com + uses: ./.github/actions/s3_upload + with: + source: ~/GBS-ROOT/local/repos/tizen/${{ matrix.gbs_build_arch }}/logs/*/*/log.txt + dest: logs/tizen_gbs_${{ matrix.gbs_build_arch }}_log.txt + s3_id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} + s3_key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} - if: matrix.gbs_build_arch == 'x86_64' name: extract test coverage result @@ -86,18 +92,14 @@ jobs: python3 .github/workflows/gen_coverage_badge.py ~/testresult/usr/share/nnstreamer/unittest/result/index.html ~/testresult/usr/share/nnstreamer/unittest/result/coverage_badge.svg - if: matrix.gbs_build_arch == 'x86_64' - name: Update github.io - run: | - git clone https://${{ secrets.TAOS_ACCOUNT }}:${{ secrets.TAOS_ACCOUNT_TOKEN }}@github.com/nnstreamer/nnstreamer.github.io.git - pushd nnstreamer.github.io - mkdir -p testresult - cp -r ~/testresult/usr/share/nnstreamer/unittest/result/* testresult - git config user.email "nnsuite@samsung.com" - git config user.name "nnsuite" - git add * - git commit -s -m "${{ steps.get-date.outputs.date }} : Update unit test result." - git push origin main -f - popd + name: update test coverage result to github.io + uses: ./.github/actions/gitpush + with: + source: ~/testresult/usr/share/nnstreamer/unittest/result/* + dest: testresult + message: "${{ steps.get-date.outputs.date }} : Update test coverage result." + taos_account: ${{ secrets.TAOS_ACCOUNT }} + taos_account_token: ${{ secrets.TAOS_ACCOUNT_TOKEN }} - name: Get nntrainer uses: actions/checkout@v4 @@ -124,12 +126,12 @@ jobs: pip install pybadges setuptools echo '${{ toJSON( needs.cache_gbs_build.outputs) }}' > gbs_build_result.json python3 .github/workflows/gen_gbs_result_badge.py gbs_build_result.json ~/testresult - git clone https://${{ secrets.TAOS_ACCOUNT }}:${{ secrets.TAOS_ACCOUNT_TOKEN }}@github.com/nnstreamer/nnstreamer.github.io.git - pushd nnstreamer.github.io - cp -r ~/testresult/*.svg testresult - git config user.email "nnsuite@samsung.com" - git config user.name "nnsuite" - git add * - git commit -s -m "Update unit test result badge." - git push origin main -f - popd + + - name: update result badge to github.io + uses: ./.github/actions/gitpush + with: + source: ~/testresult/*.svg + dest: testresult + message: "Update unit test result badge." + taos_account: ${{ secrets.TAOS_ACCOUNT }} + taos_account_token: ${{ secrets.TAOS_ACCOUNT_TOKEN }} diff --git a/.github/workflows/update_pbuilder_cache.yml b/.github/workflows/update_pbuilder_cache.yml index ccecacdb89..389cd3d780 100644 --- a/.github/workflows/update_pbuilder_cache.yml +++ b/.github/workflows/update_pbuilder_cache.yml @@ -71,11 +71,11 @@ jobs: /var/cache/pbuilder/base.tgz key: pbuilder-cache-${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles('**/debian/control') }}-${{ steps.get-date.outputs.date }} - - name: Release daily build result - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} - AWS_EC2_METADATA_DISABLED: true - run: | - aws s3 cp --recursive --region ap-northeast-2 ~/daily_build/ubuntu/ s3://nnstreamer-release/nnstreamer/${{ steps.get-date.outputs.date }}/ubuntu/ - aws s3 cp --recursive --region ap-northeast-2 ~/daily_build/ubuntu/ s3://nnstreamer-release/nnstreamer/latest/ubuntu/ + - name: Release daily build result to release.nnstreamer.com + uses: ./.github/actions/s3_upload + with: + source: ~/daily_build/ubuntu/ + dest: ubuntu/ + s3_id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} + s3_key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} + s3_option: --recursive