diff --git a/.github/workflows/devcontainer-native-release.yml b/.github/workflows/devcontainer-native-release.yml new file mode 100644 index 000000000..9eeafbbb1 --- /dev/null +++ b/.github/workflows/devcontainer-native-release.yml @@ -0,0 +1,94 @@ +name: devcontainer-native-release + +on: + push: + branches: + - main + +concurrency: + group: devcontainer-native-release-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + env: + CARGO_TOML_PATH: cmd/devcontainer-native/Cargo.toml + CRATE_DIR: cmd/devcontainer-native + TAG_PREFIX: devcontainer-native-v + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Compute next patch version + id: version + shell: bash + run: | + set -euo pipefail + git fetch --tags --force + + latest_tag=$(git tag --list "${TAG_PREFIX}*" --sort=-version:refname | head -n 1) + if [[ -z "$latest_tag" ]]; then + base_version="0.0.0" + else + base_version="${latest_tag#${TAG_PREFIX}}" + fi + + IFS='.' read -r major minor patch <<< "$base_version" + next_version="${major}.${minor}.$((patch + 1))" + next_tag="${TAG_PREFIX}${next_version}" + + echo "latest_tag=${latest_tag}" >> "$GITHUB_OUTPUT" + echo "version=${next_version}" >> "$GITHUB_OUTPUT" + echo "tag=${next_tag}" >> "$GITHUB_OUTPUT" + + - name: Set Cargo version + shell: bash + run: | + set -euo pipefail + version='${{ steps.version.outputs.version }}' + perl -0pi -e 's/^version\s*=\s*"[0-9]+\.[0-9]+\.[0-9]+"/version = "'"$version"'"/m' "$CARGO_TOML_PATH" + + - name: Build release binary + shell: bash + run: | + set -euo pipefail + cargo build --release --manifest-path "$CARGO_TOML_PATH" + + - name: Package release artifact + id: package + shell: bash + run: | + set -euo pipefail + version='${{ steps.version.outputs.version }}' + artifact_name="devcontainer-native-${version}-linux-x64.tar.gz" + tar -C "$CRATE_DIR/target/release" -czf "$artifact_name" devcontainer-native + sha256sum "$artifact_name" > "${artifact_name}.sha256" + + echo "artifact=${artifact_name}" >> "$GITHUB_OUTPUT" + + - name: Create GitHub release + env: + GH_TOKEN: ${{ github.token }} + shell: bash + run: | + set -euo pipefail + version='${{ steps.version.outputs.version }}' + tag='${{ steps.version.outputs.tag }}' + artifact='${{ steps.package.outputs.artifact }}' + + gh release create "$tag" \ + --target "$GITHUB_SHA" \ + --fail-on-no-commits \ + --title "devcontainer-native v${version}" \ + --notes "Automated release for devcontainer-native v${version}." \ + "$artifact" \ + "${artifact}.sha256" diff --git a/cmd/devcontainer-native/Cargo.lock b/cmd/devcontainer-native/Cargo.lock index eeadb1332..53746b2b0 100644 --- a/cmd/devcontainer-native/Cargo.lock +++ b/cmd/devcontainer-native/Cargo.lock @@ -4,4 +4,4 @@ version = 4 [[package]] name = "devcontainer-native" -version = "0.1.0" +version = "0.0.1" diff --git a/cmd/devcontainer-native/Cargo.toml b/cmd/devcontainer-native/Cargo.toml index 92362430a..4618f03fe 100644 --- a/cmd/devcontainer-native/Cargo.toml +++ b/cmd/devcontainer-native/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "devcontainer-native" -version = "0.1.0" +version = "0.0.1" edition = "2021" description = "Native Rust foundation for devcontainer CLI" license = "MIT"