From cffada6b3b48cf9b2fcf3fdb52025e22ecfed58a Mon Sep 17 00:00:00 2001 From: Awiteb Date: Tue, 28 May 2024 22:25:50 +0300 Subject: [PATCH] chore: Initialize actions Signed-off-by: Awiteb --- .forgejo/ISSUE_TEMPLATE/bug.md | 31 ++++++ .forgejo/ISSUE_TEMPLATE/feature_request.md | 13 +++ .forgejo/ISSUE_TEMPLATE/question.md | 12 +++ .forgejo/pull_request_template.md | 6 ++ .forgejo/workflows/cd.yml | 112 +++++++++++++++++++++ .forgejo/workflows/changelog.yml | 36 +++++++ .forgejo/workflows/ci.yml | 25 +++++ .github/workflows/auto_close_pr.yml | 34 +++++++ 8 files changed, 269 insertions(+) create mode 100644 .forgejo/ISSUE_TEMPLATE/bug.md create mode 100644 .forgejo/ISSUE_TEMPLATE/feature_request.md create mode 100644 .forgejo/ISSUE_TEMPLATE/question.md create mode 100644 .forgejo/pull_request_template.md create mode 100644 .forgejo/workflows/cd.yml create mode 100644 .forgejo/workflows/changelog.yml create mode 100644 .forgejo/workflows/ci.yml create mode 100644 .github/workflows/auto_close_pr.yml diff --git a/.forgejo/ISSUE_TEMPLATE/bug.md b/.forgejo/ISSUE_TEMPLATE/bug.md new file mode 100644 index 0000000..6629940 --- /dev/null +++ b/.forgejo/ISSUE_TEMPLATE/bug.md @@ -0,0 +1,31 @@ +--- +name: Bug +about: Create a bug report to help us improve Telepingbot +title: '...' +labels: ["Kind/Bug"] +assignees: '' +--- + +## Checks + +* [ ] I added a descriptive title to this issue +* [ ] I have searched Google for similar issues and couldn't find anything +* [ ] I have read [the README](https://git.4rs.nl/awiteb/telepingbot/src/branch/master/README.md) and still think this is a bug + +## Version + + + +Rustc version: `...` + +Telepingbot version: `...` + +## Description + + +## Expected behavior + + +## Actual behavior + diff --git a/.forgejo/ISSUE_TEMPLATE/feature_request.md b/.forgejo/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..e393526 --- /dev/null +++ b/.forgejo/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,13 @@ +--- +name: Feature request +about: Suggest an idea for Telepingbot +title: '...' +labels: ["Kind/Feature"] +assignees: '' +--- + +## Feature description + + +## Example + diff --git a/.forgejo/ISSUE_TEMPLATE/question.md b/.forgejo/ISSUE_TEMPLATE/question.md new file mode 100644 index 0000000..39546e3 --- /dev/null +++ b/.forgejo/ISSUE_TEMPLATE/question.md @@ -0,0 +1,12 @@ +--- +name: Question +about: Ask a question about Telepingbot +title: '...' +labels: ["Kind/Question"] +assignees: '' +--- + +## Question + + + diff --git a/.forgejo/pull_request_template.md b/.forgejo/pull_request_template.md new file mode 100644 index 0000000..ca6bbcf --- /dev/null +++ b/.forgejo/pull_request_template.md @@ -0,0 +1,6 @@ +## Issue + +This will fix {issue Forgejo link} + +## How I am fixing it + diff --git a/.forgejo/workflows/cd.yml b/.forgejo/workflows/cd.yml new file mode 100644 index 0000000..dbf0d49 --- /dev/null +++ b/.forgejo/workflows/cd.yml @@ -0,0 +1,112 @@ +name: CD + +on: + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+ + - v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+ + +jobs: + build-assets: + runs-on: debian + strategy: + matrix: + target: + - x86_64-unknown-linux-gnu + - x86_64-unknown-linux-musl + - aarch64-unknown-linux-gnu + - aarch64-unknown-linux-musl + - x86_64-pc-windows-gnu + steps: + - uses: actions/checkout@v4 + with: + ref: master + fetch-depth: 1 + - uses: https://codeberg.org/TheAwiteb/rust-action@v1.75 + - name: Install musl-tools + run: | + apt-get update + apt-get install -y musl-tools + if: ${{ contains(matrix.target, 'musl') }} + - name: Install gcc-aarch64-linux-gnu linker + run: | + apt-get update + apt-get install -y gcc-aarch64-linux-gnu + if: ${{ contains(matrix.target, 'aarch64') }} + - name: Install gcc-mingw-w64 linker + run: | + apt-get update + apt-get install -y gcc-mingw-w64 + if: ${{ contains(matrix.target, 'windows') }} + - name: Preparing the environment + run: | + BIN_NAME="$(echo $GITHUB_REPOSITORY | cut -d '/' -f 2)" + echo "BIN_NAME=$BIN_NAME" >> $GITHUB_ENV + mkdir -p release-dir + mkdir -p .cargo + echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' > .cargo/config.toml + echo 'target.aarch64-unknown-linux-musl.linker = "aarch64-linux-gnu-gcc"' >> .cargo/config.toml + + - name: Install the target + run: rustup target install ${{ matrix.target }} + + - name: Build the asset + run: | + APP_NAME="$BIN_NAME-$GITHUB_REF_NAME-${{ matrix.target }}" + cargo clean + cargo build --release --no-default-features --target ${{ matrix.target }} + cp target/${{ matrix.target }}/release/$BIN_NAME.exe release-dir/$APP_NAME.exe || true + cp target/${{ matrix.target }}/release/$BIN_NAME release-dir/$APP_NAME || true + cd release-dir + test -f $APP_NAME && sha256sum $APP_NAME > $APP_NAME.sha256 || true + test -f $APP_NAME.exe && sha256sum $APP_NAME.exe > $APP_NAME.exe.sha256 || true + + - uses: actions/upload-artifact@v3 + with: + name: ${{ env.GITHUB_SHA }}-${{ env.GITHUB_RUN_NUMBER }} + path: release-dir/ + + release: + needs: build-assets + runs-on: debian + steps: + - uses: actions/checkout@v4 + with: + ref: master + fetch-depth: 0 + fetch-tags: true + - uses: actions/download-artifact@v3 + with: + name: ${{ env.GITHUB_SHA }}-${{ env.GITHUB_RUN_NUMBER }} + path: ${{ env.GITHUB_WORKSPACE }}/release-dir + - name: Install git-cliff + run: | + version="2.2.1" + wget "https://github.com/orhun/git-cliff/releases/download/v$version/git-cliff-$version-x86_64-unknown-linux-gnu.tar.gz" + tar -xvzf git-cliff-*.tar.gz + mv "git-cliff-$version/git-cliff" /usr/local/bin + rm -fr git-cliff-* + - name: Write changelog + run: | + git config user.name forgejo-actions + git config user.email forgejo-actions@noreply.localhost + echo 'TAG_CHANGELOG=$(if [[ $(git tag --sort=committerdate | tail -n 1) == *"-rc"* ]]; then git-cliff --strip all $(git tag --sort=committerdate | tail -n 2 | sed ":a; N; $!ba; s/\n/../g") | sed "s/## unreleased.*$//g"; else git-cliff -l --strip all | sed "s/^## \[.*$//g";fi)' | sed "s/\"/'/g" >> $GITHUB_ENV + if [[ $(git tag --sort=creatordate | tail -n 1) != *'-rc'* ]]; then + echo "The latest tag is not a release candidate, updating changelog for $GITHUB_REF_NAME" + git-cliff > CHANGELOG.md + git add CHANGELOG.md + git commit -m "Update changelog for $GITHUB_REF_NAME" + git push + echo "Changelog updated" + else + echo "The latest tag is a release candidate, not updating changelog" + fi + - name: Create Release + uses: actions/forgejo-release@v1 + with: + direction: upload + url: https://git.4rs.nl + token: ${{ env.GITHUB_TOKEN }} + release-dir: release-dir + release-notes: ${{ env.TAG_CHANGELOG }} + prerelease: ${{ contains(env.GITHUB_REF_NAME, '-rc') }} diff --git a/.forgejo/workflows/changelog.yml b/.forgejo/workflows/changelog.yml new file mode 100644 index 0000000..3153f1e --- /dev/null +++ b/.forgejo/workflows/changelog.yml @@ -0,0 +1,36 @@ +name: Write changelog + +on: + push: + branches: + - 'master' + +jobs: + write-changelog: + runs-on: debian + steps: + - uses: actions/checkout@v4 + with: + ref: master + fetch-depth: 0 + fetch-tags: true + - name: Install git-cliff + run: | + version="2.2.1" + wget "https://github.com/orhun/git-cliff/releases/download/v$version/git-cliff-$version-x86_64-unknown-linux-gnu.tar.gz" + tar -xvzf git-cliff-*.tar.gz + mv "git-cliff-$version/git-cliff" /usr/local/bin + rm -fr git-cliff-* + - name: Write changelog + run: | + git config user.name forgejo-actions + git config user.email forgejo-actions@noreply.localhost + git-cliff > CHANGELOG.md + if [[ $(git status | grep --extended-regexp '^\s+modified:\s+CHANGELOG.md$') ]]; then + git add CHANGELOG.md + git commit -m "chore(changelog): Update changelog" + git push + echo "Changelog updated" + else + echo "No changes to changelog" + fi diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..1f6eaf0 --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,25 @@ +name: Rust CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + rust_ci: + name: Rust CI + runs-on: debian + steps: + - uses: actions/checkout@v4 + - uses: https://codeberg.org/TheAwiteb/rust-action@v1.75 + - name: Check MSRV + run: cargo +1.75 build + - name: Build the source code + run: cargo build + - name: Check the code format + run: cargo fmt -- --check + - name: Run cargo-check + run: cargo check + - name: Run cargo-clippy + run: cargo clippy -- -D warnings diff --git a/.github/workflows/auto_close_pr.yml b/.github/workflows/auto_close_pr.yml new file mode 100644 index 0000000..120863c --- /dev/null +++ b/.github/workflows/auto_close_pr.yml @@ -0,0 +1,34 @@ +name: Auto close PR + +on: + pull_request: + types: [opened, reopened] + +jobs: + close_pr: + name: Auto close PR + runs-on: ubuntu-latest + steps: + - name: Send close comment + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $PAT" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \ + -d '{"body":"${{ env.BODY }}"}' + env: + PAT: ${{ secrets.PAT }} + BODY: This repository is mirror only and you cannot create a pull request for it. Please open your PR at https://git.4rs.nl/awiteb/telepingbot + - name: Close the PR + run: | + curl -L \ + -X PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $PAT" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }} \ + -d '{"state":"closed"}' + env: + PAT: ${{ secrets.PAT }}