1# Copyright (c) 2021, 2022 Nordic Semiconductor ASA
2# SPDX-License-Identifier: Apache-2.0
3
4# Make a snapshot of open bugs as a python pickle file, compressed
5# using xz. Upload the xz file to Amazon S3.
6
7name: Bug Snapshot
8
9on:
10  workflow_dispatch:
11    branches: [main]
12  schedule:
13  # Run daily at 14:05
14  - cron: '5 14 * * *'
15
16jobs:
17  make_bugs_pickle:
18    name: Make bugs pickle
19    runs-on: ubuntu-22.04
20    if: github.repository_owner == 'zephyrproject-rtos'
21
22    steps:
23    - name: Checkout
24      uses: actions/checkout@v4
25
26    - name: Install Python dependencies
27      run: |
28        pip install -U pygithub
29
30    - name: Snapshot bugs
31      env:
32        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33      run: |
34        BUGS_PICKLE_FILENAME="zephyr-bugs-$(date -I).pickle.xz"
35        BUGS_PICKLE_PATH="${RUNNER_TEMP}/${BUGS_PICKLE_FILENAME}"
36
37        set -euo pipefail
38        python3 scripts/make_bugs_pickle.py | xz > ${BUGS_PICKLE_PATH}
39
40        echo "BUGS_PICKLE_FILENAME=${BUGS_PICKLE_FILENAME}" >> ${GITHUB_ENV}
41        echo "BUGS_PICKLE_PATH=${BUGS_PICKLE_PATH}" >> ${GITHUB_ENV}
42
43    - name: Configure AWS Credentials
44      uses: aws-actions/configure-aws-credentials@v4
45      with:
46        aws-access-key-id: ${{ vars.AWS_BUILDS_ZEPHYR_BUG_SNAPSHOT_ACCESS_KEY_ID }}
47        aws-secret-access-key: ${{ secrets.AWS_BUILDS_ZEPHYR_BUG_SNAPSHOT_SECRET_ACCESS_KEY }}
48        aws-region: us-east-1
49
50    - name: Upload to AWS S3
51      run: |
52        REPOSITORY_NAME="${GITHUB_REPOSITORY#*/}"
53
54        PUBLISH_BUCKET="builds.zephyrproject.org"
55        PUBLISH_DOMAIN="builds.zephyrproject.io"
56        if [ "${{github.event_name}}" = "schedule" ]; then
57          PUBLISH_ROOT="${REPOSITORY_NAME}/bug-snapshot/daily"
58        else
59          PUBLISH_ROOT="${REPOSITORY_NAME}/bug-snapshot"
60        fi
61
62        PUBLISH_UPLOAD_URI="s3://${PUBLISH_BUCKET}/${PUBLISH_ROOT}/${BUGS_PICKLE_FILENAME}"
63        PUBLISH_DOWNLOAD_URI="https://${PUBLISH_DOMAIN}/${PUBLISH_ROOT}/${BUGS_PICKLE_FILENAME}"
64
65        aws s3 cp --quiet ${BUGS_PICKLE_PATH} ${PUBLISH_UPLOAD_URI}
66        echo "Bug pickle is available at: ${PUBLISH_DOWNLOAD_URI}" >> ${GITHUB_STEP_SUMMARY}
67