From 45f357b84912ea88f74c8d99a41b908c325e7902 Mon Sep 17 00:00:00 2001 From: KIRED Nour Elhouda Date: Wed, 28 Dec 2022 12:03:48 +0100 Subject: [PATCH] ci(workflows): uphold okp4 actions --- .github/workflows/notify-release.yml | 22 +++++ .github/workflows/publish-pr.yml | 27 +++--- .github/workflows/publish.yml | 120 +++++++++++++++++++-------- .github/workflows/test.yml | 2 +- 4 files changed, 125 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/notify-release.yml diff --git a/.github/workflows/notify-release.yml b/.github/workflows/notify-release.yml new file mode 100644 index 0000000..04714a0 --- /dev/null +++ b/.github/workflows/notify-release.yml @@ -0,0 +1,22 @@ +name: notify-release + +on: + release: + types: [published] + +jobs: + notify-discord: + runs-on: ubuntu-22.04 + steps: + - name: Notify Discord + uses: fjogeleit/http-request-action@v1 + with: + url: ${{ secrets.OKP4_DISCORD_WEBHOOK }} + method: 'POST' + customHeaders: '{"Content-Type": "application/json"}' + data: |- + { + "avatar_url": "https://avatars.githubusercontent.com/u/98603954?v=4", + "username": "Bot Anik", + "content": "šŸšØ A new version of @${{github.repository}} ${{ github.event.release.tag_name }} has been released! šŸŽ‰\n\nšŸ‘‰ Changelog: https://github.com/${{ github.repository }}/releases/tag/${{ github.event.release.tag_name }}\nšŸ‘‰ Official repo: https://github.com/${{ github.repository }}" + } diff --git a/.github/workflows/publish-pr.yml b/.github/workflows/publish-pr.yml index 9865a13..d1cd7e3 100644 --- a/.github/workflows/publish-pr.yml +++ b/.github/workflows/publish-pr.yml @@ -4,18 +4,23 @@ on: issue_comment: types: [created, edited] -concurrency: - group: publish-${{ github.ref }} - cancel-in-progress: true - jobs: - publish-docker-image: - if: ${{ github.event.issue.pull_request && github.event.comment.body == '/publish' }} + publish-docker-images: + if: ${{ github.event.issue.pull_request && github.event.comment.body == '/publish' }} runs-on: ubuntu-22.04 steps: - - name: Set up context - id: project_context - uses: FranzDiebold/github-env-vars-action@v2.7.0 + - uses: xt0rted/pull-request-comment-branch@v1 + id: comment-branch + + - name: Check out repository + uses: actions/checkout@v3 + with: + ref: ${{ steps.comment-branch.outputs.head_ref }} + + - uses: gacts/github-slug@v1 + id: slug + with: + to-slug: ${{ steps.comment-branch.outputs.head_ref }} - name: Extract metadata (tags, labels) for Docker id: docker_metadata @@ -23,11 +28,11 @@ jobs: with: images: ghcr.io/${{ github.repository }} tags: | - type=raw,enable=${{ !endsWith(github.ref, github.event.repository.default_branch) }},value=${{ env.CI_ACTION_REF_NAME_SLUG }} + type=raw,value=${{ steps.slug.outputs.slug }} labels: | org.opencontainers.image.vendor=OKP4 - - name: Login to Docker registry + - name: Login to GHCR uses: docker/login-action@v2 with: registry: ghcr.io diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b97c0af..aafcbf2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,10 +1,12 @@ name: Publish - on: push: branches: [main] tags: ["v*"] - workflow_dispatch: + +concurrency: + group: publish-${{ github.ref }} + cancel-in-progress: true jobs: publish-docker-images: @@ -13,8 +15,82 @@ jobs: - name: Check out repository uses: actions/checkout@v3 - - name: Install environment - uses: actions/setup-python@v4 + - name: Set up context + id: project_context + uses: FranzDiebold/github-env-vars-action@v2.7.0 + + - name: Extract metadata (tags, labels) for Docker + id: docker_metadata + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }},${{ github.repository }} + tags: | + type=raw,value=nightly + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + labels: | + org.opencontainers.image.vendor=OKP4 + + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ secrets.DOCKER_REGISTRY_ID }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_REGISTRY_ID }} + password: ${{ secrets.DOCKER_HUB_REGISTRY_TOKEN }} + + - name: Build and publish image(s) + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + push: true + tags: ${{ steps.docker_metadata.outputs.tags }} + labels: ${{ steps.docker_metadata.outputs.labels }} + + dockerhub-description: + runs-on: ubuntu-22.04 + steps: + - name: Check out repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Find change in readme file + id: readme-change + uses: tj-actions/changed-files@v34 + with: + files: | + README.md + + - name: Docker Hub Description + if: steps.readme-change.outputs.any_changed == 'true' + uses: peter-evans/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKER_HUB_REGISTRY_ID }} + short-description: Docker image for https://github.com/${{ github.repository }} + password: ${{ secrets.DOCKER_HUB_REGISTRY_TOKEN }} + repository: ${{ github.repository }} + readme-filepath: README.md + + publish-pypi: + if: contains(github.ref, 'refs/tags/') + runs-on: ubuntu-22.04 + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up context + id: project_context + uses: FranzDiebold/github-env-vars-action@v2.7.0 + + - uses: actions/setup-python@v4 with: python-version: 3.9 @@ -23,34 +99,10 @@ jobs: with: poetry-version: 1.3.1 - - name: Login to Docker registry - run: | - echo ${{ secrets.DOCKER_REGISTRY_TOKEN }} | docker login ghcr.io -u ${{ secrets.DOCKER_REGISTRY_ID }} --password-stdin - - - name: Set up target version - id: project_context - run: | - version=`poetry version -s --no-ansi -n` - echo "version=${version}" >> $GITHUB_OUTPUT - echo "major=$(echo $version | cut -d. -f1)" >> $GITHUB_OUTPUT - echo "minor=$(echo $version | cut -d. -f2)" >> $GITHUB_OUTPUT - echo "revision=$(echo $version | cut -d. -f3)" >> $GITHUB_OUTPUT - echo "image=${GITHUB_REPOSITORY}" >> $GITHUB_OUTPUT - - - name: Build and publish image(s) + - name: Publish package + working-directory: ${{env.WORK_DIR}} run: | - if [[ $GITHUB_REF == refs/tags/v* ]]; then - echo "Publish docker image for branch" - docker build \ - -t ghcr.io/${{ steps.project_context.outputs.image }}:${{ steps.project_context.outputs.major }} \ - -t ghcr.io/${{ steps.project_context.outputs.image }}:${{ steps.project_context.outputs.major }}.${{ steps.project_context.outputs.minor }} \ - -t ghcr.io/${{ steps.project_context.outputs.image }}:${{ steps.project_context.outputs.version }} \ - -t ghcr.io/${{ steps.project_context.outputs.image }}:latest \ - . - else - echo "Publish docker image for nightly" - docker build \ - -t ghcr.io/${{ steps.project_context.outputs.image }}:nightly \ - . - fi - docker push ghcr.io/${{ steps.project_context.outputs.image }} --all-tags + poetry install + poetry build + echo "šŸš€ Publishing pypi package" + poetry publish -u __token__ -p "${{ secrets.PYPI_API_TOKEN }}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2e23d9f..4715ffb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: - name: Check out repository uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 with: python-version: 3.9