diff --git a/.gitea/workflows/build-push-docker.yml b/.gitea/workflows/build-push-docker.yml index 745f865..b232212 100644 --- a/.gitea/workflows/build-push-docker.yml +++ b/.gitea/workflows/build-push-docker.yml @@ -11,55 +11,84 @@ on: description: "Did the flow succeed?" value: ${{ jobs.publish.outputs.success }} -env: - REGISTRY_URL: git.tainton.uk - jobs: publish: - runs-on: ubuntu-latest - # permissions: - # packages: write - # contents: read - # attestations: write - # id-token: write - outputs: - success: ${{ steps.set_flag.outputs.success }} + name: Publish Docker Images + needs: create_release steps: - - name: Check out repository code - uses: actions/checkout@v4.1.7 + - name: Update Docker configuration + continue-on-error: true + run: | + mkdir -p /etc/default + mkdir -p /etc/docker + touch -a /etc/default/docker + touch -a /etc/docker/daemon.json + echo "DOCKER_OPTS=\"--insecure-registry ${{ vars.PACKAGES_REGISTRY_URL }}\"" >> /etc/default/docker + echo "{\"insecure-registries\": [\"${{ vars.PACKAGES_REGISTRY_URL }}\"]}" > /etc/docker/daemon.json + + - name: Get repo name + env: + REPO: ${{ gitea.repository }} + id: split + run: echo "repo=${REPO##*/}" >> $GITEA_OUTPUT + + - name: Check out repository + uses: actions/checkout@v4.2.2 with: + fetch-depth: 0 ref: ${{ inputs.release }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Log in to Gitea Package Registry + - name: Log in to Gitea Container Registry uses: docker/login-action@v3 with: - registry: ${{ env.REGISTRY_URL }} - username: ${{ gitea.actor }} - password: ${{ secrets.GITEA_TOKEN }} + registry: ${{ vars.PACKAGES_REGISTRY_URL }} + username: ${{ vars.ACTIONS_USERNAME }} + password: ${{ secrets.ACTIONS_TOKEN }} + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ vars.GHCR_USERNAME }} + password: ${{ secrets.GHCR_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 with: images: | - ${{ env.REGISTRY_URL }}/${{ gitea.repository }} - tags: | - type=semver,pattern=v{{version}},value=${{ inputs.release }} + ghcr.io/${{ vars.GHCR_USERNAME }}/${{ steps.split.outputs.repo }} + ${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }} + tags: type=semver,pattern=v{{version}},value=${{ inputs.release }} - - name: Build and push Docker image - id: push + - name: Print metadata + run: | + printf "Annotations:\n${{ steps.meta.outputs.annotations }}" + echo "" + printf "Labels:\n${{ steps.meta.outputs.labels }}" + echo "" + printf "Tags:\n${{ steps.meta.outputs.tags }}" + + - name: Build images uses: docker/build-push-action@v6 with: context: . - push: true + push: false + load: true + annotations: ${{ steps.meta.outputs.annotations }} labels: ${{ steps.meta.outputs.labels }} - tags: | - ${{ env.REGISTRY_URL }}/${{ gitea.repository }}:latest - ${{ env.REGISTRY_URL }}/${{ gitea.repository }}:${{ inputs.release }} + tags: ${{ steps.meta.outputs.tags }} + - name: Push images + run: | + strtags="${{ steps.meta.outputs.tags }}" + readarray -t lines <<<"$strtags" + for element in "${lines[@]}"; do docker push "$element"; done + unset strtags lines + - name: Set success flag id: set_flag run: echo "success=true" >> "$GITEA_OUTPUT" diff --git a/.gitea/workflows/create-release-old.yml b/.gitea/workflows/create-release-old.yml index 3bdee60..f3c9a3c 100644 --- a/.gitea/workflows/create-release-old.yml +++ b/.gitea/workflows/create-release-old.yml @@ -17,34 +17,83 @@ jobs: release_name: ${{ steps.tag_version.outputs.new_tag }} success: ${{ steps.set_flag.outputs.success }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.2.2 with: fetch-depth: 0 - name: Changes since last tag id: changes run: | - CHANGES=$(git log $(git describe --tags --abbrev=0)..HEAD --no-merges --oneline) - echo "$CHANGES" - if [ -z "$CHANGES" ]; then echo "changes=false" >> "$GITEA_OUTPUT"; else echo "changes=true" >> "$GITEA_OUTPUT"; fi + rm -f .changes .changes_feat .changes_fix .changes_dep .changes_other + git log $(git describe --tags --abbrev=0)..HEAD --no-merges --oneline >> .changes + cat .changes + if [[ -z $(grep '[^[:space:]]' .changes) ]] ; then + echo "changes=false" + echo "changes=false" >> "$GITEA_OUTPUT" + else + echo "changes=true" + echo "changes=true" >> "$GITEA_OUTPUT" + grep -i "feat" .changes >> .changes_feat + grep -i "fix" .changes >> .changes_fix + grep -i "dependencies" .changes >> .changes_dep + grep -i "other" .changes >> .changes_other + fi - - name: Bump version and push tag - id: tag_version - if: steps.changes.outputs.changes == 'true' - uses: mathieudutour/github-tag-action@v6.2 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - default_bump: minor - # default_bump: false + - name: Cancel if no changes + if: steps.changes.outputs.changes == 'false' + run: exit 1 - - name: Create a GitHub release + - name: Create changelog + id: create_changelog if: steps.changes.outputs.changes == 'true' - uses: ncipollo/release-action@v1 + run: | + rm -f .changelog + if [[ -z $(grep '[^[:space:]]' .changes_feat) ]] ; then + printf "## 🚀 Features" > .changelog + cat .changes_feat >> .changelog + fi + if [[ -z $(grep '[^[:space:]]' .changes_fix) ]] ; then + printf "## 🐛 Bug Fixes" >> .changelog + cat .changes_fix >> .changelog + fi + if [[ -z $(grep '[^[:space:]]' .changes_dep) ]] ; then + printf "## 📦 Dependencies" >> .changelog + cat .changes_dep >> .changelog + fi + if [[ -z $(grep '[^[:space:]]' .changes_other) ]] ; then + printf "## 💬 Other" >> .changelog + cat .changes_other >> .changelog + fi + + - name: Set server URL + id: set_srvurl + run: | + SRVURL=$(echo "${{ gitea.server_url }}" | sed 's/https:\/\/\(.*\)/\1/') + echo "srvurl=$SRVURL" >> "$GITEA_OUTPUT" + + - name: Get next version + uses: TriPSs/conventional-changelog-action@v6 + id: get_next_version with: - tag: ${{ steps.tag_version.outputs.new_tag }} - name: ${{ steps.tag_version.outputs.new_tag }} - body: ${{ steps.tag_version.outputs.changelog }} - generateReleaseNotes: true + git-url: ${{ steps.set_srvurl.outputs.srvurl }} + github-token: ${{ gitea.token }} + skip-commit: true + release-count: 1 + output-file: false + create-summary: true + skip-on-empty: true + skip-version-file: true + skip-tag: true + + - name: Create release + id: create_release + uses: akkuman/gitea-release-action@v1 + env: + NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18 + with: + tag: ${{ steps.get_next_version.outputs.tag }} + name: ${{ steps.get_next_version.outputs.tag }} + body_path: .changelog - name: Set success/fail flag id: set_flag diff --git a/.gitea/workflows/create-release.yml b/.gitea/workflows/create-release.yml index f3c9a3c..6a9981c 100644 --- a/.gitea/workflows/create-release.yml +++ b/.gitea/workflows/create-release.yml @@ -1,4 +1,4 @@ -name: Create Release +name: Release on: workflow_call: outputs: @@ -13,63 +13,41 @@ jobs: create_release: name: Create Release runs-on: ubuntu-latest + # needs: test outputs: - release_name: ${{ steps.tag_version.outputs.new_tag }} - success: ${{ steps.set_flag.outputs.success }} + release_name: ${{ steps.get_next_version.outputs.tag }} steps: - - uses: actions/checkout@v4.2.2 + - name: Check out repository + uses: actions/checkout@v4.2.2 with: fetch-depth: 0 - name: Changes since last tag id: changes run: | - rm -f .changes .changes_feat .changes_fix .changes_dep .changes_other + rm -f .changes git log $(git describe --tags --abbrev=0)..HEAD --no-merges --oneline >> .changes cat .changes + + - name: Check for changes + run: | if [[ -z $(grep '[^[:space:]]' .changes) ]] ; then echo "changes=false" echo "changes=false" >> "$GITEA_OUTPUT" else echo "changes=true" echo "changes=true" >> "$GITEA_OUTPUT" - grep -i "feat" .changes >> .changes_feat - grep -i "fix" .changes >> .changes_fix - grep -i "dependencies" .changes >> .changes_dep - grep -i "other" .changes >> .changes_other - fi + fi - name: Cancel if no changes if: steps.changes.outputs.changes == 'false' run: exit 1 - - name: Create changelog - id: create_changelog - if: steps.changes.outputs.changes == 'true' - run: | - rm -f .changelog - if [[ -z $(grep '[^[:space:]]' .changes_feat) ]] ; then - printf "## 🚀 Features" > .changelog - cat .changes_feat >> .changelog - fi - if [[ -z $(grep '[^[:space:]]' .changes_fix) ]] ; then - printf "## 🐛 Bug Fixes" >> .changelog - cat .changes_fix >> .changelog - fi - if [[ -z $(grep '[^[:space:]]' .changes_dep) ]] ; then - printf "## 📦 Dependencies" >> .changelog - cat .changes_dep >> .changelog - fi - if [[ -z $(grep '[^[:space:]]' .changes_other) ]] ; then - printf "## 💬 Other" >> .changelog - cat .changes_other >> .changelog - fi - - name: Set server URL id: set_srvurl run: | SRVURL=$(echo "${{ gitea.server_url }}" | sed 's/https:\/\/\(.*\)/\1/') - echo "srvurl=$SRVURL" >> "$GITEA_OUTPUT" + echo "srvurl=$SRVURL" >> "$GITEA_OUTPUT" - name: Get next version uses: TriPSs/conventional-changelog-action@v6 @@ -77,6 +55,8 @@ jobs: with: git-url: ${{ steps.set_srvurl.outputs.srvurl }} github-token: ${{ gitea.token }} + preset: "conventionalcommits" + # preset: "angular" # This is the default skip-commit: true release-count: 1 output-file: false @@ -86,16 +66,10 @@ jobs: skip-tag: true - name: Create release - id: create_release - uses: akkuman/gitea-release-action@v1 - env: - NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18 - with: - tag: ${{ steps.get_next_version.outputs.tag }} - name: ${{ steps.get_next_version.outputs.tag }} - body_path: .changelog - - - name: Set success/fail flag - id: set_flag - if: steps.changes.outputs.changes == 'true' - run: if test "${{ steps.changes.outputs.changes }}" = "true"; then echo "success=true" >> "$GITEA_OUTPUT"; else echo "success=false" >> "$GITEA_OUTPUT"; fi + run: | + curl -s -X POST \ + -H "Authorization: token ${{ secrets.ACTIONS_TOKEN }}" \ + -H "accept: application/json" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\": \"${{ steps.get_next_version.outputs.tag }}\", \"name\": \"${{ steps.get_next_version.outputs.tag }}\", \"body\": \"${{ steps.get_next_version.outputs.changelog }}\"}" \ + "${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases"